Qt Connecting SIGNAL and SLOT in object member of MainWindow

那年仲夏 提交于 2019-12-02 03:42:34
jpo38

You must have MyClass inherit from QObject AND add Q_OBJECT macro in your MyClass definition (header file) to have slots/signals work.

class MyClass : public QObject
{
     Q_OBJECT

public:
     ....
};

Inheriting QObject is the right way, but your still missing Qt-Meta Object Code. Your header-file for your class should look like this:

#ifndef MYCLASS_H
#define MYCLASS_H

class MyClass : public QObject {
    Q_OBJECT
    // your methods, variables, slots and signals
}

#endif

Don't forget to create the moc file, the easiest way is to use qmake or the QtCreator IDE.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!