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
Qt Code:
  1. #ifndef TRYFUTURE_H
  2. #define TRYFUTURE_H
  3.  
  4. #include <QtGui>
  5. #include <QDialog>
  6. #include <QMessageBox>
  7. #include <QTime>
  8. #include <qtconcurrentrun.h>
  9. #include <QThread>
  10.  
  11. namespace Ui {
  12. class tryfuture;
  13. }
  14.  
  15. class tryfuture: public QWidget
  16. {
  17. Q_OBJECT
  18. int pagenumber;
  19. public:
  20. explicit tryfuture(QWidget *parent = 0);
  21. ~tryfuture();
  22. public slots:
  23. void test1();
  24. void test2();
  25. void test3();
  26. private:
  27. Ui::tryfuture*ui;
  28. };
  29. #endif //
To copy to clipboard, switch view to plain text mode 

tryfuture.cpp
Qt Code:
  1. tryfuture::tryfuture(QWidget *parent) :
  2. QWidget(parent),
  3. ui(new Ui::tryfuture)
  4. {
  5.  
  6. QTimer *changetimer= new QTimer(this);
  7. connect(changetimer, SIGNAL(timeout()), this, SLOT(changepage()));
  8. changetimer->start(10000);
  9.  
  10. }
  11.  
  12. void tryfuture::changepage(){
  13.  
  14. QFuture<void> future;
  15.  
  16. switch(pagenumber%3)
  17. {
  18. case 0:
  19. future = QtConcurrent::run(this, &tryfuture::test1);
  20. break;
  21. case 1:
  22. future = QtConcurrent::run(this, &tryfuture::test2);
  23. break;
  24. case 2:
  25. future = QtConcurrent::run(this, &tryfuture::test3);
  26. break;
  27. }
  28.  
  29. pagenumber++;
  30. }
  31. void tryfuture::test1(){
  32. QMessageBox::information(this, tr("Qt Example 1"),
  33. tr("The function my_func has finished."));
  34. }
  35.  
  36. void tryfuture::test2(){
  37. QMessageBox::information(this, tr("Qt Example 2"),
  38. tr("The function my_func has finished."));
  39. }
  40. void formUretimBilgiEkrani::test3(){
  41. QMessageBox::information(this, tr("Qt Example 3"),
  42. tr("The function my_func has finished."));
  43. }
To copy to clipboard, switch view to plain text mode