简体   繁体   English

转换Visual C ++项目以增强构建Makefile项目时,Qt信号和插槽中断

[英]Qt Signals and Slots break when converting Visual C++ project to boost build makefile project

I created a Visual C++ Project using MSVS and I just made another project in MSVS so that the same code can be built using boost build. 我使用MSVS创建了一个Visual C ++项目,而我刚刚在MSVS中创建了另一个项目,以便可以使用boost build构建相同的代码。 I can currently build my project using a Visual C++ project as well as a Makefile project that uses boost build. 我目前可以使用Visual C ++项目以及使用Boost构建的Makefile项目来构建我的项目。 There is a difference between the two builds though concerning QT Signals and Slots.For the following code,when I call MyThread::Start() the onTimeout() slot is called when the project is built in visual studio, but not called when built using boost build. 两者之间在QT信号和插槽方面存在差异。对于以下代码,当我调用MyThread::Start()时,在Visual Studio中构建项目时会调用onTimeout()插槽,但在构建时不会调用使用增强构建。

class MyThread: public QObject{
    Q_OBJECT
public:
    bool start();
public Q_SLOTS:
    void onTimeout();
private:
    QThread m_thread;
    QTimer m_timer;
};
void MyThread::start()
{
    m_timer.start(1000);
    m_thread.setObjectName(QString("GigeControl"));
    m_thread.start();
    m_timer.moveToThread(&m_thread);
}
void MyThread::onTimeout()
{
    //Do Stuff

}

I am really having a hard time trying to figure out the differences between the two builds,especially since I need those signals and slots to work. 我真的很难弄清楚这两个版本之间的差异,特别是因为我需要这些信号和插槽来工作。 One major difference that I have noticed so far is that the Visual C++ project is built using /Zp1 so all structures are 1 byte alligned. 到目前为止,我注意到的一个主要区别是Visual C ++项目是使用/Zp1构建的,因此所有结构都是1个字节。 This is not done in the boost project as I don't know how to. 由于我不知道如何在boost项目中未完成此操作。 I've seen people on the internet mentioning that structure allignments (especially using #pragma pack can cause problems with QT). 我曾在互联网上看到有人提到结构规范(尤其是使用#pragma pack可能会导致QT问题)。

If anyone has some experience they might be able to share it would be greatly appreciated. 如果有人有经验,他们也许可以分享,将不胜感激。

It looks like the problem was in fact the structure packing. 看起来问题实际上是结构包装。 I am writing code for a couple of code bases that are being merged and there coincidentally happens to be some packing conflicts. 我正在为几个正在合并的代码库编写代码,并且碰巧碰巧存在一些打包冲突。 To fix the packing for building with boost-build all I had to to was add this to the lib being generated in the Jamfile: 要修复使用boost-build构建的包装,我所要做的就是将其添加到Jamfile中生成的lib中:

    lib foo
:
    ...
:
    ...
    <target-os>linux:<cxxflags>-fpack-struct=1
    <target-os>windows:<cxxflags>-Zp1
;

This worked for me so hopefully it will help someone else out if they get stuck here too 这对我有用,所以希望如果有人也被困在这里,它将帮助别人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM