开发者

c++ connect signal

开发者 https://www.devze.com 2023-01-05 18:34 出处:网络
I got this thread.h file; #ifndef THREAD_H #define THREAD_H #include <Q开发者_运维技巧tGui>

I got this thread.h file;

#ifndef THREAD_H
#define THREAD_H

#include <Q开发者_运维技巧tGui>
#include <QString>

#include <tray.h>
class svThread : public QThread {

    public:
        bool getIsPaused();
        void checkSettings();
        virtual void run();
        void setPause(bool);
signals:
        void mySignal(bool);
};

#endif // THREAD_H

and I got an tray application, named tray :P where i make a thread;

svThread a;

and I'm starting it.

in tray.h I also got a slot

class Tray : public QWidget
{
    Q_OBJECT

public:
    Tray();
    QMenu *trayIconMenu;

    public slots:
        void settings();
        void pause();
        void setPause(bool);

public:
    void createActions();
    void createTrayIcon();

    QAction *settingAction;
    QAction *quitAction;
    QAction *pauseAction;
    QSystemTrayIcon *trayIcon;
};

#endif

But how can I make that when I use setPause(); in the thread.cpp file that he calls setPause(); in the tray.cpp file?


You just need to connect each pair of object's signals and slots just as you would normally. Take a look at Qt's documentation on the subject which is very good. Basically it is:

connect(threadObj, SIGNAL(mySignal(bool)), trayObj, SLOT(setPause(bool)));


Try Queued Connections. Just supply fifth argument of connect Qt::QueuedConnection

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号