私のthreadcheck.h
#include <QThread>
#include <QDebug>
#include <QMutex>
class ThreadCheck : public QThread
{
Q_OBJECT
public:
explicit ThreadCheck(QObject *parent = 0);
int Val() const;
signals:
void signalReceived();
protected:
void run();
public slots:
void slotReceived();
private:
QMutex mutex;
int num;
};
私のthreadcheck.cppファイルは
#include "threadcheck.h"
ThreadCheck::ThreadCheck(QObject *parent) :
QThread(parent)
{
connect(this,SIGNAL(signalReceived()),this,SLOT(slotReceived()));
num = 0;
}
int ThreadCheck::Val() const
{
return num;
}
void ThreadCheck::slotReceived()
{
mutex.lock();
qDebug() << "hello";
mutex.unlock();
}
void ThreadCheck::run()
{
while(1)
{
emit signalReceived();
}
}
メイン.cppは
#include <QCoreApplication>
#include "threadcheck.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ThreadCheck threadCheck;
threadCheck.start();
while(1);
return a.exec();
}
このスレッドを main から開始すると、実行されない出力スロットは表示されません。理想的には、hello を出力し続ける必要があります。
解決策を提案してください。