我有我的主線程負責GUI和我的工作線程負責與我的攝像頭做東西。爲什麼我的工作線程沒有收到這個信號?
我能夠從我的主線程發出一個信號到我的攝像頭線程,但它永遠不會收到它!有人可以解釋我爲什麼嗎?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setThreadsAndObj();
setConnects();
startCamera();
}
void MainWindow::setThreadsAndObj()
{
cameraClassPtr = new cameraClass();
cameraThread = new QThread();
}
void MainWindow::setConnects()
{
....
connect(this, &MainWindow::savePicture, cameraClassPtr, &cameraClass::takePicture);
}
void MainWindow::startCamera()
{
//camera start
connect(cameraThread, &QThread::started, cameraClassPtr, &cameraClass::getVideoFrame);
connect(cameraThread, &QThread::finished, cameraClassPtr, &QThread::deleteLater);
connect(cameraThread, &QThread::finished, cameraThread, &QThread::deleteLater);
//receive camera frames
connect(cameraClassPtr, &cameraClass::videoFrameToGui, this, &MainWindow::updateCameraStream);
//start threads
cameraClassPtr->moveToThread(cameraThread);
cameraThread->start();
}
void MainWindow::foo()
{
emit savePicture();
}
void cameraClass::takePicture()
{
qDebug()<<"camera class received signal"; //THIS NEVER GETS PRINTED
}
有人可以解釋我爲什麼我的信號從來沒有收到和「相機類接收信號」從未打印和如何解決這個問題?
嘗試更改'cameraThread = new QThread();'''cameraThread = new QThread(this);' – eyllanesc
@eyllanesc有什麼區別? – traducerad
@eyllanesc解決了它。我在我的工作線程中有一段時間1循環。我不得不添加QApplication :: processEvents();在while循環中。對不起,讓你失去時間。 – traducerad