Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort crashing on QT 5.9.9

QSerialPort crashing on QT 5.9.9

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 341 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    ven1ceBeach
    wrote on last edited by ven1ceBeach
    #1

    Hello,

    I am trying to write a simple application with serial connection. Somehow it crashes everytime.

    I added

    QT       += serialport
    

    Header:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QSerialPort>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    private slots:
        //void serialReceived();
    
    private:
        Ui::MainWindow *ui;
    
        QSerialPort *serial;
    
    };
    #endif // MAINWINDOW_H
    

    CPP:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QDebug>
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
    
        serial->setPortName("COM1");
        //serial->open(QSerialPort::ReadWrite);
        //serial->setBaudRate(QSerialPort::Baud115200);
        //serial->setDataBits(QSerialPort::Data8);
        //serial->setParity(QSerialPort::NoParity);
        //serial->setStopBits(QSerialPort::OneStop);
        //serial->setFlowControl(QSerialPort::NoFlowControl);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    

    As you can see I commented out a lot of code, just to show you that absolutely the simplest tries don't work.

    The only error I am getting is:

    23:31:58: The program has unexpectedly finished.
    23:31:58: The process was ended forcefully.
    

    Does somebody has a clue why it crashes?

    INFO: The code above is shortened. There is also a TCP Server and Client running in this application but I do not think it interferes with the SerialPort. Without the SerialPort stuff the programm is running fine.

    Further, uncommenting the stuff does not solve the error.

    Best Wishes,
    Andi

    Ketan__Patel__0011K 1 Reply Last reply
    0
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by
      #2

      @ven1ceBeach said in QSerialPort crashing on QT 5.9.9:

      serial->setPortName("COM1");

      You are using the object serial without it's creation.
      create object of serial using new.

      1 Reply Last reply
      2
      • V ven1ceBeach

        Hello,

        I am trying to write a simple application with serial connection. Somehow it crashes everytime.

        I added

        QT       += serialport
        

        Header:

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        
        #include <QMainWindow>
        #include <QSerialPort>
        
        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
        private slots:
            //void serialReceived();
        
        private:
            Ui::MainWindow *ui;
        
            QSerialPort *serial;
        
        };
        #endif // MAINWINDOW_H
        

        CPP:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        #include <QDebug>
        
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
        
            serial->setPortName("COM1");
            //serial->open(QSerialPort::ReadWrite);
            //serial->setBaudRate(QSerialPort::Baud115200);
            //serial->setDataBits(QSerialPort::Data8);
            //serial->setParity(QSerialPort::NoParity);
            //serial->setStopBits(QSerialPort::OneStop);
            //serial->setFlowControl(QSerialPort::NoFlowControl);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        
        

        As you can see I commented out a lot of code, just to show you that absolutely the simplest tries don't work.

        The only error I am getting is:

        23:31:58: The program has unexpectedly finished.
        23:31:58: The process was ended forcefully.
        

        Does somebody has a clue why it crashes?

        INFO: The code above is shortened. There is also a TCP Server and Client running in this application but I do not think it interferes with the SerialPort. Without the SerialPort stuff the programm is running fine.

        Further, uncommenting the stuff does not solve the error.

        Best Wishes,
        Andi

        Ketan__Patel__0011K Offline
        Ketan__Patel__0011K Offline
        Ketan__Patel__0011
        wrote on last edited by
        #3

        @ven1ceBeach said in QSerialPort crashing on QT 5.9.9:

        serial

        Please Assign Memory For You QSerialPort Object

          serial = new QSerialPort();
          serial->setPortName("COM1");
          //// Your Code ////
        
        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved