Qextserialport crashes
-
Hello to everyone
I made a simple code for communication with a lpc2138 board through com port but my code chrashes after about 10 seconds, I made my code in lpc to send data all the time.
Here are the source files:untitled.pro
@QT += core guiTARGET = untitled
TEMPLATE = appSOURCES += main.cpp
untitledmainwindow.cppHEADERS += untitledmainwindow.h
FORMS += untitledmainwindow.ui
include(C:/Users/Martin/Desktop/qextserialpor/src/qextserialport.pri)@
main.cpp
@#include <QtGui/QApplication>
#include "untitledmainwindow.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
untitledMainWindow w;
w.show();return a.exec();
}
@untitledmainwindow.h
@#ifndef UNTITLEDMAINWINDOW_H
#define UNTITLEDMAINWINDOW_H#include <QMainWindow>
#include "qextserialport.h"namespace Ui {
class untitledMainWindow;
}class untitledMainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit untitledMainWindow(QWidget *parent = 0);
~untitledMainWindow();private slots:
void onDataAvailable();private:
Ui::untitledMainWindow *ui;
QextSerialPort *port;
};#endif // UNTITLEDMAINWINDOW_H@
untitledmainwindow.cpp
@#include "untitledmainwindow.h"
#include "ui_untitledmainwindow.h"untitledMainWindow::untitledMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::untitledMainWindow)
{
ui->setupUi(this);port = new QextSerialPort("COM9"); port->setBaudRate(BAUD9600); port->setDataBits(DATA_8); port->setParity(PAR_NONE); port->setFlowControl(FLOW_OFF); port->setStopBits(STOP_1); port->open(QIODevice::ReadOnly); connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
}
void untitledMainWindow::onDataAvailable()
{
QByteArray data;
data.resize(1);port->read(data.data(), data.size()); ui->lineEdit->setText(data.data());
}
untitledMainWindow::~untitledMainWindow()
{
delete ui;
}@Please help!!
-
Instead of QextSerialPort try use "QtSerialPort":http://qt-project.org/wiki/QtSerialPort.
-
I made a delay in the lpc code, I send 10 bytes in second, and now its ok.
Anyway thank you kuzulis and cincirin