Hi guys,

I created this Qt Application project under VS2005, and tried to display the GPS data onto GUI---real simple. I can read the data from the serial port fine (using QExtSerialPort class) but I cant display it on the GUI for some reason. The GUI would just be non-responsive and I have to kill it. If you guys could help me out here, that'd be great. I tried to compare this to other existing tutorials I have been working on, but couldnt find anything. In particular, I simply call label->setText() to display the string :

Qt Code:
  1. #ifndef QTAPP_H
  2. #define QTAPP_H
  3.  
  4. #include <QtGui/QMainWindow>
  5. #include "ui_qtapp.h"
  6. #include <QLabel>
  7. #include <QIODevice>
  8. #include <QString>
  9. #include <QApplication>
  10. #include <QStringList>
  11. #include <QDebug>
  12. #include <QVariant>
  13. #include <QWidget>
  14. #include "qextserialport.h"
  15.  
  16. class QtApp : public QMainWindow
  17. {
  18. Q_OBJECT
  19.  
  20. public:
  21. QtApp(QWidget *parent = 0, Qt::WFlags flags = 0);
  22. ~QtApp();
  23. void Run();
  24.  
  25. private:
  26. Ui::QtAppClass ui;
  27. QString* str;
  28. QStringList* list;
  29. QextSerialPort* port;
  30. };
  31.  
  32. #endif // QTAPP_H
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "qtapp.h"
  2.  
  3. QtApp::QtApp(QWidget *parent, Qt::WFlags flags)
  4. : QMainWindow(parent, flags)
  5. {
  6. ui.setupUi(this);
  7.  
  8. str = new QString;
  9. list = new QStringList;
  10. port = new QextSerialPort( "COM1" );
  11. port->setBaudRate(BAUD115200);
  12. port->setFlowControl(FLOW_OFF);
  13. port->setParity(PAR_NONE);
  14. port->setDataBits(DATA_8);
  15. port->setStopBits(STOP_1);
  16.  
  17. // Open port
  18. port->open( QIODevice::ReadOnly );
  19. }
  20.  
  21. QtApp::~QtApp()
  22. {
  23.  
  24. }
  25.  
  26. void QtApp::Run()
  27. {
  28. char data[100];
  29.  
  30. QLabel* label = new QLabel;
  31. while(1)
  32. {
  33. if( !port->bytesAvailable() ) continue;
  34.  
  35. int charIdx = 0;
  36. int bytesRead;
  37.  
  38. //
  39. // Find sync word
  40. do
  41. {
  42. data[charIdx] = 'A';
  43. port->read( data,
  44. 1 );
  45. } while( data[charIdx] != '$' );
  46. charIdx++;
  47.  
  48. //
  49. // Read the rest of the data
  50. do
  51. {
  52. charIdx += port->read( &data[charIdx],
  53. 1 );
  54. } while( data[charIdx-1] != '*' );
  55.  
  56.  
  57. // Read check sum
  58. charIdx += port->read( &data[charIdx],
  59. 2 );
  60. data[charIdx] = '\0';
  61.  
  62.  
  63. // Copy buffer to QString
  64. *str = data;
  65.  
  66. //
  67. // Diplay this on GUI
  68. label->setText( *str );
  69. }
  70. }
To copy to clipboard, switch view to plain text mode