So I have got some code to compile, but I'm having some problems. Here is what I'm doing to give you an idea of what's going on with my code:


  • I have C code with which I create a thread to run the GUI in
  • In the GUI code I create a QThread which provides me entry points to write data to and from.


I can compile it all and run it, but it seems as though the GUI Thread is blocking my Main thread. The graphics show up, but everything else in my main C code is not executing.

My GUI code:
Qt Code:
  1. //globals
  2. idThread *idthread;
  3. MainWindow *window;
  4.  
  5. int hpgeUI(char *argv[])
  6. //int main(int argc, char *argv[])
  7. {
  8. rdac = new QApplication(argc, argv, QApplication::GuiServer);
  9. idthread = new idThread;
  10. window = new MainWindow;
  11.  
  12. window->showFullScreen(); //Run in full screen mode
  13. window->setPalette(QPalette(QColor(233, 233, 235))); //Set palette color to off white
  14. window->setAutoFillBackground(true); //Fill background w/ palette color
  15. window->show();//Show window
  16. rdac->connect(idthread, SIGNAL(newIdValue(int)), window, SLOT(newIdValue(int)));
  17. //return 0;
  18. return rdac->exec();
  19. }
  20.  
  21. void updateData(int id)
  22. {
  23. idthread->updateID(id);
  24. }
To copy to clipboard, switch view to plain text mode 


The QThread to pass data to and from the C code:
Qt Code:
  1. void idThread::updateID(int id)
  2. {
  3. /* Lock the mutex so we can grab the data */
  4. QMutexLocker locker(&mutex);
  5. /* copy the id to our thread's copy */
  6. this->localID = id;
  7. /* if the thread is not running, start it, else restart the thread. */
  8. if(!isRunning()){
  9. start(LowPriority);
  10. } else {
  11. restart = true;
  12. /* wake up the thread if necessary */
  13. condition.wakeOne();
  14. }
  15. }
  16.  
  17. void idThread::run()
  18. {
  19. cout << "Running idThread\n";
  20. int id = 0;
  21. forever //Qt psuedo-keyword, like foreach
  22. {
  23. /* Lock the mutex and copy ID to a local copy so that if new ID's come in, we can get them immediately */
  24. mutex.lock();
  25. id = this->localID;
  26. mutex.unlock();
  27. /* if we get an abort for some reason, break from this loop and kill the thread */
  28. if(abort)
  29. return;
  30. /* Emit the new ID unless restart is true */
  31. if(!restart)
  32. emit newIdValue(id);
  33. /* Once we're done with all the iterations, we call QWaitCondition::wait() to put the thread */
  34. /* to sleep by calling, unless restart is true. There's no use in keeping a worker thread looping */
  35. /* indefinitely while there's nothing to do. */
  36. mutex.lock();
  37. if(!restart)
  38. condition.wait(&mutex);
  39. restart = false;
  40. mutex.unlock();
  41. }
  42.  
  43. }
To copy to clipboard, switch view to plain text mode 


My C Code that puts everything together:

Qt Code:
  1. void *initUI(char *argv[]) {
  2. printf("This is the initUI thread\n");
  3. hpgeUI(argv);
  4. return 0;
  5. }
  6.  
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.  
  11. pthread_t ui;
  12. pthread_create(&ui, NULL, initUI(argv), 0);
  13. printf("Done initializing...\n");
  14. int x = 0, test = 0x1;
  15. while(1)
  16. {
  17. x++;
  18. if(x%50 == 0) {
  19. printf("Testing with value: 0x%04x\n", test);
  20. if(test < 0x8)
  21. test++;
  22. else
  23. test = 0x1;
  24. updateData(test);
  25. }
  26. }
  27. return 0;
  28. }
To copy to clipboard, switch view to plain text mode 



Am I going about it all wrong? Again, I appreciate all the help.

Regards,
BB