
Originally Posted by
Lykurg
Using [QTCLASS]So connect the finished signal of f1 to a slot where you can go on, after the work in the function is done.
If I do like this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this->ui->button1, SIGNAL(clicked()), this, SLOT(startThread()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::startThread()
{
QFuture<void> f1 = QtConcurrent::run(this, &MainWindow::mbox);
//f1.waitForFinished();
}
void MainWindow::mbox()
{
for (int i=0; i < 20000; i++)
{
qDebug() << i;
}
emit done();
}
void MainWindow::done()
{
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this->ui->button1, SIGNAL(clicked()), this, SLOT(startThread()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::startThread()
{
QFuture<void> f1 = QtConcurrent::run(this, &MainWindow::mbox);
//f1.waitForFinished();
}
void MainWindow::mbox()
{
for (int i=0; i < 20000; i++)
{
qDebug() << i;
}
emit done();
}
void MainWindow::done()
{
QMessageBox::aboutQt(this, "Done!");
}
To copy to clipboard, switch view to plain text mode
It apparently tries and create widget from within the thread and fails. Could you please hint me?
Bookmarks