Hello Friends,

I am having problems of communication between Thread and my MainWindowForm.

Inside the Thread I run a method for upgrading the QTableView, I am getting more errors.

Here Class Header:

Qt Code:
  1. class ThreadNotify : public QThread
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. ThreadNotify(QObject *parent = 0);
  7. virtual ~ThreadNotify();
  8.  
  9. void setCapsule(MainWindowForm *pointMainCapsule);
  10.  
  11. MainWindowForm *accessMainCapsule;
  12.  
  13. void setMessage(const QString &message);
  14. void stop();
  15.  
  16. signals:
  17.  
  18. void transactionStarted(const QString &message);
  19.  
  20. ....
  21.  
  22. protected:
  23.  
  24. void run();
  25. ....
  26. };
  27.  
  28. class MainWindowForm : public QMainWindow, public Ui::MainWindowForm
  29. {
  30. Q_OBJECT
  31.  
  32. public:
  33.  
  34. MainWindowForm(QWidget *parent = 0);
  35. virtual ~MainWindowForm();
  36.  
  37. ThreadNotify instanceThreadNotify;
  38. QSqlQueryModel *model;
  39.  
  40. void modelRefresh();
  41. ...
  42. }
To copy to clipboard, switch view to plain text mode 

Here Code:

Qt Code:
  1. ThreadNotify::ThreadNotify(QObject *parent)
  2. : QThread (parent)
  3. {
  4. stopped = false;
  5. }
  6.  
  7. ThreadNotify::~ThreadNotify()
  8. {
  9. /** Destroys the object and frees any allocated resources */
  10. }
  11.  
  12. void ThreadNotify::setCapsule(MainWindowForm *pointMainCapsule)
  13. {
  14. accessMainCapsule = pointMainCapsule;
  15. }
  16.  
  17. ....
  18.  
  19. void ThreadNotify::run()
  20. {
  21. while (!stopped == nnotifies < N_NOTIFICATIONS)
  22. {
  23. int sock;
  24. fd_set input_mask;
  25.  
  26. sock = PQsocket(conn);
  27.  
  28. if (sock < 0)
  29. break;
  30.  
  31. FD_ZERO(&input_mask);
  32. FD_SET(sock, &input_mask);
  33.  
  34. if (select(sock + 1, &input_mask, NULL, NULL, NULL) < 0)
  35. {
  36. (void)exit_nicely(conn);
  37. }
  38.  
  39. PQconsumeInput(conn);
  40.  
  41. while ((notify = PQnotifies(conn)) != NULL)
  42. {
  43. qApp->lock();
  44.  
  45. accessMainCapsule->modelRefresh();
  46.  
  47. qApp->unlock();
  48. PQfreemem(notify);
  49. nnotifies++;
  50. }
  51. }
  52.  
  53. PQfinish(conn);
  54. stopped = false;
  55. }
  56.  
  57. ...
  58.  
  59. MainWindowForm::MainWindowForm(QWidget *parent)
  60. : QMainWindow(parent)
  61. {
  62. ...
  63. }
  64.  
  65. void MainWindowForm::modelRefresh()
  66. {
  67. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  68.  
  69. model->setQuery(QString("SELECT ....");
  70.  
  71. if (model->lastError().isValid())
  72. {
  73. qDebug() << model->lastError();
  74. }
  75.  
  76. QApplication::restoreOverrideCursor();
  77. }
  78.  
  79. ...
To copy to clipboard, switch view to plain text mode 

When I receive the notification of PostgreSQL running on the Thread, the method of class MainWindowForm is triggered.

More get the following error:

=======ERROR====================================
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registered using qRegisterMetaType().)

Notify ==> ASYNC NOTIFY trigger 'nalertupdatetab' backend pid 21611
=======ERROR====================================

I used something similar in Qt3 with QDataTable, and not had that problem, someone could help me with that?

Thanks, edm.