Results 1 to 4 of 4

Thread: Connect ReadyRead-Signal with Slot

  1. #1
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Connect ReadyRead-Signal with Slot

    Hi,
    I am working on a project another student has written.
    I don't like the way he handled reading from the SerialPort:

    Qt Code:
    1. settings->RS485port.write(dataToSend);
    2. if(settings->RS485port.waitForReadyRead(1)){
    3. QByteArray temp = settings->RS485port.readAll();
    4.  
    5. for(int charCount = 0; charCount < temp.count(); charCount++){
    6. ...... //handling the response
    7. }
    8. byteReceived = true;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    waitForReadyRead let the GUI freeze and that's definitely not what i want to happen. So i read about connecting the readyRead Signal with a Slot.

    Qt Code:
    1. connect(settings->RS485port, SIGNAL(readyRead()), this, SLOT(handlePortReadyRead()));
    To copy to clipboard, switch view to plain text mode 

    If I try to compile this, it says:
    C:\Users\...\bootloaderdialog.cpp:207: Fehler: no matching function for call to 'BootloaderDialog::connect(QSerialPort&, const char [13], BootloaderDialog* const, const char [23])'
    connect(settings->RS485port, SIGNAL(readyRead()), this, SLOT(handlePortReadyRead()));
    Do you know why i can't connect the Signal to the Slot. Or do you know any better way to read Data from a Serialport?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connect ReadyRead-Signal with Slot

    The first parameter should be the object address.

  3. #3
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Connect ReadyRead-Signal with Slot

    Thank You. That was very obvious, couldn't see that.
    Last edited by mikrocat; 6th November 2015 at 10:48.

  4. #4
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Connect ReadyRead-Signal with Slot

    Okay so I connected the Signal to the Slot

    This is my handlePortReadyRead Slot:
    Qt Code:
    1. QByteArray temp = RS485port.readAll();
    2. for(int charCount = 0; charCount < temp.count(); charCount++){
    3. char singleInChar = temp.at(charCount);
    4. validationFlag = handleResponse(&response, deviceAddr, FID, singleInChar, false);
    5. if(validationFlag){
    6. if(response.at(0) != 0){ // device sent error code
    7. displayErrorMessage(response.at(0));
    8. }
    9. emit readCompleteFrame();
    10. break;
    11. }
    12. }
    13. byteReceived = true;
    To copy to clipboard, switch view to plain text mode 

    I'm having a process, where I write many times to the port and then want to analyse the response. At the moment it looks like this:

    Qt Code:
    1. RS485Port.write(dataToSend);
    2. timer->start(100);
    3. do{
    4. QApplication::processEvents();
    5. if(validationFlag){
    6. ...
    7. //do something with the response
    8. response.clear();
    9. }
    10. else if(timer->remainingTime() == 0){
    11. ... //check if no connection or no valid Frame
    12. }
    13. }
    14. while(!validationFlag);
    To copy to clipboard, switch view to plain text mode 

    So this process is a very long process. Sometimes it get stucked in the middle of the code, I think it is because of the QApplication:rocessEvents().
    Is there any better way?

Similar Threads

  1. Replies: 2
    Last Post: 15th September 2010, 00:54
  2. Can't connect a signal to a slot
    By cejohnsonsr in forum Newbie
    Replies: 5
    Last Post: 26th August 2010, 20:42
  3. How to connect signal/slot in QItemEditorFactory?
    By yyalli in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2010, 14:56
  4. problem connect signal - slot
    By jaca in forum Newbie
    Replies: 13
    Last Post: 9th March 2010, 19:38
  5. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55

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.