小编Mar*_*utz的帖子

更改QCheckBox的复选框位置

我在网格布局中有一个QCheckbox,定义如下:

self.isSubfactorCheckbox = QtGui.QCheckBox('Is &subfactor', self)
Run Code Online (Sandbox Code Playgroud)

默认情况下,该复选框位于"Is subfactor"文本的左侧.我希望将其移至案文右侧.

我试过玩次控制位置,但无济于事.

self.isSubfactorCheckbox.setStyleSheet('QCheckBox::indicator{subcontrol-origin: content; subcontrol-position: top right;}')
Run Code Online (Sandbox Code Playgroud)

这会将复选框向右移动(它仍然在文本的左侧),但它会将文本向右推出窗口的边缘.

这无助于将文本移到右侧:

self.isSubfactorCheckbox.setStyleSheet('QCheckBox::text{subcontrol-origin: content; subcontrol-position: top left; }')
Run Code Online (Sandbox Code Playgroud)

一个解决方案是创建一个QLabel并在其右侧添加复选框,但我没有找到一种方法来在QLabel中加下划线字母,以便用户知道哪个是快捷键.我已经尝试用字母前缀字母和/或将它们包装在<u> </u>标签中.

我仍然只想使用QLabel,但是如何在没有文本被推出的情况下将复选框切换到文本的右侧.

qt pyqt pyqt4 qcheckbox

4
推荐指数
1
解决办法
7340
查看次数

在不使用未命名的命名空间的情况下在标头中隐藏C++类

我正在编写一个C++标头,我在其中定义了一个

class A {
   // ...
};
Run Code Online (Sandbox Code Playgroud)

我想隐藏在外面的世界(因为它可能会更改甚至在此标题的未来版本中被删除).

在同一个头文件中还有一个B类,它有一个A类对象作为成员:

class B {
public:
   // ...

private:
   A a_;
};
Run Code Online (Sandbox Code Playgroud)

什么是从外界隐藏A级的正确方法?

如果我将A的定义放在未命名的命名空间中,编译器会发出警告,所以我认为,由于内部链接的问题,我应该做其他事情.

c++ namespaces pimpl-idiom header forward-declaration

4
推荐指数
2
解决办法
3984
查看次数

将部分专用模板作为模板参数传递

我有一个类模板,期望一些其他模板作为参数:

template<
    class Key, 
    template <typename K,template <typename T> class Allocator> class Policy
>
class container {
     Policy<Key,Allocator>* _policy;
     //some code here
};
Run Code Online (Sandbox Code Playgroud)

通常我将它与策略类一起使用,如下所示:

template <class Key,template <typename T> class Allocator> class policy {
    //some code
};
Run Code Online (Sandbox Code Playgroud)

但是如果我必须将额外的模板参数传递给策略类呢?就像是:

template <time_t Age,class Key,template <typename T> class Allocator> class policy_3 {
    //some code
};
Run Code Online (Sandbox Code Playgroud)

我该怎么办,允许该类用户通过Age paratemeter而不接触其他人?例如:

typedef container<key_type,policy_3<100500> > containerWithAge;
Run Code Online (Sandbox Code Playgroud)

c++ templates metaprogramming

4
推荐指数
1
解决办法
1084
查看次数

Boost函数:存储boost :: bind返回的任何函数?

我想编写一个异步计时器,在经过一定时间后调用一个函数.现在我希望能够使用boost::bind()任何特定间隔过去后定时器调用的签名来绑定函数.我现在这样做的方式受到boost线程的启发,它有一些抽象的基类来存储线程函数.这就是我做的:

        class TimedFunctionBase
        {
        public:
            virtual void call() = 0;
        };

        typedef std::shared_ptr<TimedFunctionBase> TimedFunctionBasePtr;

        template<class F>
        class TimedFunction : public TimedFunctionBase
        {
        public:
            TimedFunction(F _f):
            m_function(_f)
            {
            }

            void call()
            {
                m_function();
            }

        private:
            F m_function;
        };
Run Code Online (Sandbox Code Playgroud)

然后,在timer函数内部,我只需保存回调,如下所示:

MyAsyncTimer
{
private:
    TimedFunctionBasePtr m_callback;
};
Run Code Online (Sandbox Code Playgroud)

并在定时函数内调用它

m_callback->call();
Run Code Online (Sandbox Code Playgroud)

我的问题其实非常简单:boost是否已经提供了一种机制来实现这一目标?经过长时间的搜索后,我找不到太多内容,内部boost::thread也看起来好像没有为这种用途预定义.也许boost::function_base?文档说你可能不会直接创建它.有提升方式,还是我必须自己编写这些容器类?

c++ boost function

4
推荐指数
1
解决办法
877
查看次数

C++ lambda表达式无法编译

我正在cin使用lambda表达式尝试在循环索引中使用循环索引的值:

#include<iostream>
using namespace std;

int main(){
  for(int a, ([](int & b){cin>>b;})(a); a < 2; ++a);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这些是我在ubuntu上使用g ++ 4.5编译时的错误:

forLoopAndCinTest.c++: In function ‘int main()’:
forLoopAndCinTest.c++:5:14: error: expected unqualified-id before ‘[’ token
forLoopAndCinTest.c++:5:14: error: expected ‘)’ before ‘[’ token
forLoopAndCinTest.c++:5:34: error: expected primary-expression before ‘)’ token
forLoopAndCinTest.c++:5:34: error: expected ‘;’ before ‘)’ token
forLoopAndCinTest.c++:5:40: error: name lookup of ‘a’ changed for ISO ‘for’ scoping
forLoopAndCinTest.c++:5:40: note: (if you use ‘-fpermissive’ G++ will accept your code)
forLoopAndCinTest.c++:5:50: …
Run Code Online (Sandbox Code Playgroud)

c++ lambda compiler-errors c++11

4
推荐指数
1
解决办法
2197
查看次数

不使用local.xml进行magento中的主题开发

我听说很多Magento社区的人都提到了使用local.xmlMagento主题开发的好处

我能理解其中的好处,实际上我无法想到任何使用它可能有害的情况.

是否存在特定情况local.xml?如果有,那会是什么?

magento

4
推荐指数
1
解决办法
661
查看次数

c++11 速度比较/成本 std::hash&lt;std::string&gt; equal 与 std::string equal 直接在 2 个大字符串上

您好,我对 std::hash 有一个问题,如果我有 2 个大字符串进行比较,并且我愿意接受 std::hash 在大多数情况下比较相等,那么执行类似以下操作而不是直接执行操作是否更符合性能字符串比较?还要考虑这将在循环中读取文件,因此它将被执行多次,这是大文件的问题。

std::string largeString1;  // large but not huge meaning a line of text like up to lets say 500 chars 
std::string largeString2;

// is this better than then next block in terms of performance and if so by how much?
if ( std::hash<std::string>(largeString1) == std::hash<std::string>(largeString2) )
{
// true logic
}

// is this a lot slower than the previous
if ( largeString1 == largeString2 )
{
// true logic
}
Run Code Online (Sandbox Code Playgroud)

hash c++11 stdhash

4
推荐指数
1
解决办法
6685
查看次数

获取标准输入并将其作为字符串存储在lisp中

我意识到这可能是一个非常愚蠢的问题,但我不知道为什么这不起作用,我几乎放弃了.基本上我试过:

(setq answer (string (read)))
Run Code Online (Sandbox Code Playgroud)

(setq answer 0)
(format answer "~s" (read))
Run Code Online (Sandbox Code Playgroud)

(setq answer (read))
Run Code Online (Sandbox Code Playgroud)

当我试图评估

(if (stringp answer) 
    (princ "works")
    (princ "failed"))
Run Code Online (Sandbox Code Playgroud)

在任何上述尝试中,它总是出现失败.

我究竟做错了什么?

lisp string stdin common-lisp

3
推荐指数
2
解决办法
6778
查看次数

如何在C ++中的Windows中获取设备属性?

在Windows中,如果打开设备管理器->右键单击设备->属性->详细信息,则会得到{Property,Value}对。我想在Visual Studio的C ++代码中访问它们。我如何得到它?

谢谢,

c++ winapi properties device

3
推荐指数
1
解决办法
7099
查看次数

MSVC的内联命名空间模拟(10.0/11.0)

有没有办法模拟inline namespaceMSVC?

LLVM的libc ++使用它来创建一个隐藏的版本化命名空间,如下所示:

#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE {
#define _LIBCPP_END_NAMESPACE_STD  } }
#define _VSTD std::_LIBCPP_NAMESPACE
namespace std {
  inline namespace _LIBCPP_NAMESPACE {
  }
}
Run Code Online (Sandbox Code Playgroud)

并在GCC上仿效它,如下所示:

#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace _LIBCPP_NAMESPACE {
#define _LIBCPP_END_NAMESPACE_STD  } }
#define _VSTD std::_LIBCPP_NAMESPACE

namespace std {
namespace _LIBCPP_NAMESPACE {
}
using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题是,我如何用MSVC实现同样的目标?如果不可能的话,我会很高兴找到一个没有版本化的解决方案(现在),我想这将是

#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {
#define _LIBCPP_END_NAMESPACE_STD }
#define _VSTD std
Run Code Online (Sandbox Code Playgroud)

但有点失败的目的......

c++ namespaces visual-c++ c++11 inline-namespaces

3
推荐指数
1
解决办法
1397
查看次数