Results 1 to 12 of 12

Thread: if USB serial cable is unplugged, there is a serialPortError Problem !

  1. #1
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default if USB serial cable is unplugged, there is a serialPortError Problem !

    i use ;

    connect(mySerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this,
    SLOT(handleError(QSerialPort::SerialPortError)));

    ...

    void MyClass::handleError(QSerialPort::SerialPortError error)
    {
    if (error == QSerialPort::ResourceError) {
    QMessageBox::critical(this, tr("Critical Error"), serial->errorString());
    closeSerialPort();
    }
    }

    BUT
    if USB serial cable is unplugged, my program wants to stay in " if (error == QSerialPort::ResourceError) {...} " loop so always give me error message despite close the error messages again and again.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    The message box uses a nested event loop to process events.
    Since you have not closed the port yet you are just getting more errors, resulting in entering the same slots over and over again.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    i got it but i used closeSerialPort() function after message to close opened port ... what can i do more to fix it ?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    Quote Originally Posted by hazel View Post
    i got it but i used closeSerialPort() function after message to close opened port ... what can i do more to fix it ?
    If you close it after the message, what do you think happens if an error occurs while you are showing the message?

    Cheers,
    _

  5. #5
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !


    Added after 5 minutes:


    Quote Originally Posted by anda_skoa View Post
    If you close it after the message, what do you think happens if an error occurs while you are showing the message?

    Cheers,
    _
    you r right ;-) but still i dont know what can i do for that ... i used all cases after your message .
    Note : i'm beginner
    Last edited by hazel; 18th December 2015 at 12:30.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    Have you tried closing before showing the message box?

    Cheers,
    _

  7. #7
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    Quote Originally Posted by anda_skoa View Post
    Have you tried closing before showing the message box?

    Cheers,
    _
    Yep, because of that program has unexpectedly finished.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    Maybe you invalidate "serial" inside closeSerialPort.
    If so you need to get the error string before calling closeSerialPort.

    Cheers,
    _

  9. #9
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    i did , QT terminal example is like that but not work ... thank you , i will try to other way if i find ;-)
    Last edited by hazel; 18th December 2015 at 13:54.

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

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !


  11. #11
    Join Date
    Dec 2015
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    Heyy... i just want to share ; actually this problem about Linux operating system ( i m using ROSA ),
    Ä° dont have same problem in Windows so use different way in linux ;-)

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

    Default Re: if USB serial cable is unplugged, there is a serialPortError Problem !

    https://bugreports.qt.io/browse/QTBUG-50052 ?

    now it works for you after this patch? have you tested it now (for 5.6)?

Similar Threads

  1. Replies: 1
    Last Post: 11th December 2013, 20:37
  2. Help with serial Problem
    By Danny Fan in forum Newbie
    Replies: 5
    Last Post: 21st September 2011, 07:47
  3. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 14:59
  4. QFtp Unplug cable
    By josepvr in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2008, 14:38
  5. serial communication problem
    By Tavit in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2008, 12:56

Tags for this Thread

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.