aekilic
13th November 2014, 21:41
Dear All
I have problem about my application which is Qt 4.8.1 when using QFuture and QtConcurrent i get error code
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::startTimer: timers cannot be started from another thread
QObject::setParent: Cannot set parent, new parent is in a different thread
And also my application keep crushing unexpectedly. I never know when it going to crush.
I would be so happy is someone can help me.
Here is my code
tryfuture.h
#ifndef TRYFUTURE_H
#define TRYFUTURE_H
#include <QtGui>
#include <QDialog>
#include <QMessageBox>
#include <QTime>
#include <qtconcurrentrun.h>
#include <QThread>
namespace Ui {
class tryfuture;
}
class tryfuture: public QWidget
{
Q_OBJECT
int pagenumber;
public:
explicit tryfuture(QWidget *parent = 0);
~tryfuture();
public slots:
void test1();
void test2();
void test3();
private:
Ui::tryfuture*ui;
};
#endif //
tryfuture.cpp
tryfuture::tryfuture(QWidget *parent) :
QWidget(parent),
ui(new Ui::tryfuture)
{
QTimer *changetimer= new QTimer(this);
connect(changetimer, SIGNAL(timeout()), this, SLOT(changepage()));
changetimer->start(10000);
}
void tryfuture::changepage(){
QFuture<void> future;
switch(pagenumber%3)
{
case 0:
future = QtConcurrent::run(this, &tryfuture::test1);
break;
case 1:
future = QtConcurrent::run(this, &tryfuture::test2);
break;
case 2:
future = QtConcurrent::run(this, &tryfuture::test3);
break;
}
pagenumber++;
}
void tryfuture::test1(){
QMessageBox::information(this, tr("Qt Example 1"),
tr("The function my_func has finished."));
}
void tryfuture::test2(){
QMessageBox::information(this, tr("Qt Example 2"),
tr("The function my_func has finished."));
}
void formUretimBilgiEkrani::test3(){
QMessageBox::information(this, tr("Qt Example 3"),
tr("The function my_func has finished."));
}
I have problem about my application which is Qt 4.8.1 when using QFuture and QtConcurrent i get error code
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::startTimer: timers cannot be started from another thread
QObject::setParent: Cannot set parent, new parent is in a different thread
And also my application keep crushing unexpectedly. I never know when it going to crush.
I would be so happy is someone can help me.
Here is my code
tryfuture.h
#ifndef TRYFUTURE_H
#define TRYFUTURE_H
#include <QtGui>
#include <QDialog>
#include <QMessageBox>
#include <QTime>
#include <qtconcurrentrun.h>
#include <QThread>
namespace Ui {
class tryfuture;
}
class tryfuture: public QWidget
{
Q_OBJECT
int pagenumber;
public:
explicit tryfuture(QWidget *parent = 0);
~tryfuture();
public slots:
void test1();
void test2();
void test3();
private:
Ui::tryfuture*ui;
};
#endif //
tryfuture.cpp
tryfuture::tryfuture(QWidget *parent) :
QWidget(parent),
ui(new Ui::tryfuture)
{
QTimer *changetimer= new QTimer(this);
connect(changetimer, SIGNAL(timeout()), this, SLOT(changepage()));
changetimer->start(10000);
}
void tryfuture::changepage(){
QFuture<void> future;
switch(pagenumber%3)
{
case 0:
future = QtConcurrent::run(this, &tryfuture::test1);
break;
case 1:
future = QtConcurrent::run(this, &tryfuture::test2);
break;
case 2:
future = QtConcurrent::run(this, &tryfuture::test3);
break;
}
pagenumber++;
}
void tryfuture::test1(){
QMessageBox::information(this, tr("Qt Example 1"),
tr("The function my_func has finished."));
}
void tryfuture::test2(){
QMessageBox::information(this, tr("Qt Example 2"),
tr("The function my_func has finished."));
}
void formUretimBilgiEkrani::test3(){
QMessageBox::information(this, tr("Qt Example 3"),
tr("The function my_func has finished."));
}