//mainwindow.cpp
.....
flasher = new Flasher(0);
.....
connect(ThreadFlasher, SIGNAL(started()), flasher, SLOT(process())); // This works, process function in flasher runs
connect(this, SIGNAL(stopThread()), flasher, SLOT(stopThread()));
connect(this, SIGNAL(startFlash()), flasher, SLOT(startFlash()));
...
void MainWindow::on_pushButtonFW_clicked()
{
emit startFlash();
}
void MainWindow::on_openButtonConnect_clicked()
{
flasher->moveToThread(ThreadFlasher);
ThreadFlasher->start();
}
....
//Flasher.cpp
void Flasher::process()
{
while(run)
{
msleep(10); // I think There is not enough time to get variable startFlashing?
if(startFlashing)
{
FLASH_StartFlash();
startFlashing = false;
}
}
emit finished();
}
void Flasher::startFlash()
{
startFlashing = true;
}
void Flasher::stopThread()
{
run = false;
}
//mainwindow.cpp
.....
ThreadFlasher = new QThread;
flasher = new Flasher(0);
.....
connect(ThreadFlasher, SIGNAL(started()), flasher, SLOT(process())); // This works, process function in flasher runs
connect(this, SIGNAL(stopThread()), flasher, SLOT(stopThread()));
connect(this, SIGNAL(startFlash()), flasher, SLOT(startFlash()));
...
void MainWindow::on_pushButtonFW_clicked()
{
emit startFlash();
}
void MainWindow::on_openButtonConnect_clicked()
{
flasher->moveToThread(ThreadFlasher);
ThreadFlasher->start();
}
....
//Flasher.cpp
void Flasher::process()
{
while(run)
{
msleep(10); // I think There is not enough time to get variable startFlashing?
if(startFlashing)
{
FLASH_StartFlash();
startFlashing = false;
}
}
emit finished();
}
void Flasher::startFlash()
{
startFlashing = true;
}
void Flasher::stopThread()
{
run = false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks