Results 1 to 6 of 6

Thread: setting QSerialPort port

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default setting QSerialPort port

    The program crashes when I try to set qserialport instance setting, such as setBaudRate. it causes segmentation fault.
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. #include <QtCore/QCoreApplication>
    5. #include <QtCore/QDebug>
    6.  
    7. #include <QtSerialPort/QSerialPort>
    8. #include <QtSerialPort/QSerialPortInfo>
    9.  
    10. QT_USE_NAMESPACE
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. QApplication a(argc, argv);
    15. MainWindow w;
    16. w.show();
    17.  
    18.  
    19. QSerialPort serial;
    20.  
    21. QString path;
    22.  
    23. path.append("/dev/ttyS0");
    24.  
    25. serial.setBaudRate(QSerialPort::Baud9600);
    26.  
    27. serial.close();
    28.  
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    As my system is Linux, should I use a posix version of the function to open port!
    like:
    Qt Code:
    1. posix_openpt()
    To copy to clipboard, switch view to plain text mode 

    i would thank if run the code in your system n see if you get the same segmentation fault when setting port settings.

  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: setting QSerialPort port

    I did not crash. What am I doing wrong?

    PS:
    1. Before posting the nonsense, you'd at least have checked that you have causes crash...
    2. Also you didn't read documentation and didn't look examples. Otherwise you wouldn't write this nonsense.

    I won't answer any more your questions about QtSerialPort.



    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QtSerialPort/QSerialPort>
    4. #include <QtSerialPort/QSerialPortInfo>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. w.show();
    11.  
    12. QSerialPort serial;
    13.  
    14. QString path;
    15.  
    16. path.append("/dev/ttyS0");
    17.  
    18. serial.setBaudRate(QSerialPort::Baud9600);
    19.  
    20. serial.close();
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: setting QSerialPort port

    Quote Originally Posted by kuzulis View Post
    I did not crash. What am I doing wrong?

    PS:
    1. Before posting the nonsense, you'd at least have checked that you have causes crash...
    2. Also you didn't read documentation and didn't look examples. Otherwise you wouldn't write this nonsense.
    first of all, this was the exact qt doc. example, I shortened. second, you never have to reply to any post, this is the second time you are replying nonsensely and aggressively to my post. please NEVER EVER REPLY TO MY POSTS.
    Last edited by wysota; 27th April 2013 at 07:34. Reason: missing [/quote]

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting QSerialPort port

    I think what kuzulis meant was your statement about posix_openpt().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2013
    Posts
    1
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: setting QSerialPort port

    I think you have to use QSerialPort as a pointer

    I don't have the documentation in front of me, but here's some pseudo code:

    Qt Code:
    1. QSerialPort *serial;
    2. serial->setName("MYPORT");
    3. serial->open();
    4. serial->setBaudRate(9600);
    To copy to clipboard, switch view to plain text mode 

    I distinctly remember the little terminal GUI example that comes with QSerialPort was immensely helpful.

  6. #6
    Join Date
    Feb 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setting QSerialPort port

    Hello,

    I distinctly remember the little terminal GUI example that comes with QSerialPort was immensely helpful.
    agree
    Last edited by wally123; 17th May 2013 at 09:53.

Similar Threads

  1. Qt5 cmake and QSerialPort
    By Chris.Burner in forum Newbie
    Replies: 1
    Last Post: 21st April 2013, 16:13
  2. Need help setting up a serial port connection
    By jvwlong in forum Qt Programming
    Replies: 5
    Last Post: 3rd July 2012, 17:50
  3. Setting Source Port for QUdpSocket
    By MSUdom5 in forum Qt Programming
    Replies: 0
    Last Post: 12th April 2012, 13:15
  4. setting port in qexserialport
    By Myx in forum Newbie
    Replies: 2
    Last Post: 15th April 2011, 15:49
  5. Replies: 1
    Last Post: 16th June 2009, 09:09

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.