Results 1 to 2 of 2

Thread: QtSerialport Inconsistant Connection Issue

  1. #1
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QtSerialport Inconsistant Connection Issue

    I have used this library in the past for Qt4 but I am currently attempting to use it on a project that involves a lot more incoming data. When I attempt to connect to the correct COM port in my program, it shows no packets being received and throws no errors saying it failed to connect. When I use another terminal program it shows the constant flow of data. After several attempts to connect to the COM port my program finally shows data flowing correctly. I need my program to be able to consistently connect to a COM port when commanded. If there is anyone that has any ideas about what could be wrong with my code I would really appreciate your assistance.

    #include <QtSerialPort/QSerialPort>
    #include <QtSerialPort/QSerialPortInfo>

    void MainWindow::comportSelected()
    {
    // If some other serial port is open then close it.
    if(serial.isOpen())
    serial.close();

    if(ui->comportList->currentIndex() != 0)
    {
    serial.setDataBits(QSerialPort:ata8);
    serial.setFlowControl(QSerialPort::NoFlowControl);
    serial.setBaudRate(QSerialPort::Baud115200);
    serial.setParity(QSerialPort::NoParity);
    serial.setPort(comPortList.at(ui->comportList->currentIndex()-1));

    if(!serial.open(QIODevice::ReadWrite))
    {
    QMessageBox::critical(this, tr("Error"), serial.errorString());
    ui->console->setEnabled(false);

    }

    else
    {
    connect((const QObject*)&serial, SIGNAL(readyRead()), this, SLOT(processPendingSerialData()));

    }
    }
    else serial.close();
    }I then read like:

    void MainWindow:rocessPendingSerialData()
    {
    // While there are bytes in the buffer.
    while(serial.bytesAvailable() > 0)
    {
    // Read a byte.
    serial.read((char *)&ch, 1);

    etc...

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtSerialport Inconsistant Connection Issue

    You have a wrong initialization sequence.

    At first need to do open() and then do setup properties, please read documentation and look examples.

  3. The following user says thank you to kuzulis for this useful post:

    awpitt13 (12th December 2013)

Similar Threads

  1. QtSerialport windows problem
    By danics in forum Qt Programming
    Replies: 15
    Last Post: 12th September 2013, 20:25
  2. Replies: 2
    Last Post: 9th September 2013, 22:12
  3. inconsistant doubleclick edit behavior with qtableview
    By BreakBad in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2013, 01:45
  4. cannot build qtserialport
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2011, 05:56
  5. Replies: 1
    Last Post: 2nd April 2010, 06:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.