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 :
#ifndef QTAPP_H
#define QTAPP_H
#include <QtGui/QMainWindow>
#include "ui_qtapp.h"
#include <QLabel>
#include <QIODevice>
#include <QString>
#include <QApplication>
#include <QStringList>
#include <QDebug>
#include <QVariant>
#include <QWidget>
#include "qextserialport.h"
{
Q_OBJECT
public:
QtApp
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~QtApp();
void Run();
private:
Ui::QtAppClass ui;
QextSerialPort* port;
};
#endif // QTAPP_H
#ifndef QTAPP_H
#define QTAPP_H
#include <QtGui/QMainWindow>
#include "ui_qtapp.h"
#include <QLabel>
#include <QIODevice>
#include <QString>
#include <QApplication>
#include <QStringList>
#include <QDebug>
#include <QVariant>
#include <QWidget>
#include "qextserialport.h"
class QtApp : public QMainWindow
{
Q_OBJECT
public:
QtApp(QWidget *parent = 0, Qt::WFlags flags = 0);
~QtApp();
void Run();
private:
Ui::QtAppClass ui;
QString* str;
QStringList* list;
QextSerialPort* port;
};
#endif // QTAPP_H
To copy to clipboard, switch view to plain text mode
#include "qtapp.h"
QtApp
::QtApp(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
port = new QextSerialPort( "COM1" );
port->setBaudRate(BAUD115200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
// Open port
}
QtApp::~QtApp()
{
}
void QtApp::Run()
{
char data[100];
while(1)
{
if( !port->bytesAvailable() ) continue;
int charIdx = 0;
int bytesRead;
//
// Find sync word
do
{
data[charIdx] = 'A';
port->read( data,
1 );
} while( data[charIdx] != '$' );
charIdx++;
//
// Read the rest of the data
do
{
charIdx += port->read( &data[charIdx],
1 );
} while( data[charIdx-1] != '*' );
// Read check sum
charIdx += port->read( &data[charIdx],
2 );
data[charIdx] = '\0';
// Copy buffer to QString
*str = data;
//
// Diplay this on GUI
label->setText( *str );
}
}
#include "qtapp.h"
QtApp::QtApp(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
str = new QString;
list = new QStringList;
port = new QextSerialPort( "COM1" );
port->setBaudRate(BAUD115200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
// Open port
port->open( QIODevice::ReadOnly );
}
QtApp::~QtApp()
{
}
void QtApp::Run()
{
char data[100];
QLabel* label = new QLabel;
while(1)
{
if( !port->bytesAvailable() ) continue;
int charIdx = 0;
int bytesRead;
//
// Find sync word
do
{
data[charIdx] = 'A';
port->read( data,
1 );
} while( data[charIdx] != '$' );
charIdx++;
//
// Read the rest of the data
do
{
charIdx += port->read( &data[charIdx],
1 );
} while( data[charIdx-1] != '*' );
// Read check sum
charIdx += port->read( &data[charIdx],
2 );
data[charIdx] = '\0';
// Copy buffer to QString
*str = data;
//
// Diplay this on GUI
label->setText( *str );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks