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 gui

    TARGET = untitled
    TEMPLATE = app

    SOURCES += main.cpp
    untitledmainwindow.cpp

    HEADERS += 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&#40;&#41;;
    

    }
    @

    untitledmainwindow.h
    @#ifndef UNTITLEDMAINWINDOW_H
    #define UNTITLEDMAINWINDOW_H

    #include <QMainWindow>
    #include "qextserialport.h"

    namespace Ui {
    class untitledMainWindow;
    }

    class untitledMainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    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 try to adapted your code on my serial port reader. I have no crash, I'm using qextserialport 1.2. In what line stops(crash) your application ?



  • I made a delay in the lpc code, I send 10 bytes in second, and now its ok.
    Anyway thank you kuzulis and cincirin


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.