Results 1 to 20 of 20

Thread: (Callback API) and (Qt - SIGNAL/SLOT)

  1. #1
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy (Callback API) and (Qt - SIGNAL/SLOT)

    Is it possivel to derived Qt Project from a callback API and link it to:
    connect(this, SIGNAL(callback_api_function), this, SLOT(processData_to_tablewidget));

    I just want to get the event from the "callback_API" and data parameter, and providing it to a tablewidget.

    Thanks in advance.

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

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    No, the signal has to be a Qt signal. You might register a callback from the callback api and there either call the slot directly or use a dummy QObject that will emit the signal for you.

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

    pytro (8th March 2007)

  4. #3
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Qt Code:
    1. class GuiApp : public QMainWindow, public GPListener( callback API-Class), public Thread
    2.  
    3. public:
    4. void newPeer (const char *pszNodeUUID); // implemented on GPListener
    5. ...
    6. private slots:
    7. void processPeerUpdate(QString p);
    8. ...
    9. };
    10.  
    11. inline void GuiApp::newPeer (const char *pszNodeUUID)
    12. {
    13. emit processPeerUpdate(pszNodeUUID);
    14. }
    To copy to clipboard, switch view to plain text mode 

    Gives me a run time Error when:
    Qt Code:
    1. ui.tableWidget->setItem(0,0,pszNodeUUID);
    To copy to clipboard, switch view to plain text mode 

    I can't understand the register process.. is it possible to explain it with more detail please.

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

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    What is the error?

  6. The following user says thank you to wysota for this useful post:

    pytro (14th March 2007)

  7. #5
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    It is on Release mode, i can't build Qt in Debug mode on Runtime.
    The process is:

    Image 1 - It reveals that the program is running with no problems; and is waiting for a newpeer.
    Image 2 - On the moment i launch the other peer/program, this error ocorrs.
    Image 3 - After the click on break button.

    When i debug manually, it passes all functions but only when is going to post "pszNodeUUID" on the tablewidget, the error appears.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    What is that Thread class? Aren't you accessing the GUI from a non-GUI thread?

  9. The following user says thank you to jacek for this useful post:

    pytro (14th March 2007)

  10. #7
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    hi, not using it @ll now, no problems with that.
    Here is little history of my Qt work, working perfectly:
    image 1 - main.
    image 2 - connect(..).
    image 3 - processOneThing invoked to update tablewidget.
    image 4 - postEvent to invoke customEvent ( on image 5 ).
    image 5 - tablewidget updated.

    video - A little demo video..

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    What is the value of pszNodeUUID (in hex)?

  12. The following user says thank you to jacek for this useful post:

    pytro (14th March 2007)

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

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    image 1 - main.
    image 2 - connect(..).
    image 3 - processOneThing invoked to update tablewidget.
    image 4 - postEvent to invoke customEvent ( on image 5 ).
    image 5 - tablewidget updated.

    video - A little demo video..
    Could you in future please post the code in textual form instead of placing external images? Images come and go whereas the text would remain here as others might face simmilar problems in future and would benefit from this thread. And besides, such images make the thread less readable. Thank you.

  14. The following user says thank you to wysota for this useful post:

    pytro (14th March 2007)

  15. #10
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    @jacek
    Sorry, how do i do that(reading in hex) - the working application or the other?
    @wysota
    Ok i'll do that, sorry.

  16. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    Sorry, how do i do that(reading in hex)
    Just print it on the console using qDebug().

    Quote Originally Posted by pytro View Post
    the working application or the other?
    The non-working one.

  17. The following user says thank you to jacek for this useful post:

    pytro (8th March 2007)

  18. #12
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Going to do that tomorrow morning.. thanks for the help!

  19. #13
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by jacek View Post
    Just print it on the console using qDebug().


    The non-working one.
    It is a Qt Application, not a console application.

    Qt Code:
    1. inline void GuiApp::newPeer (const char *pszNodeUUID)
    2. {
    3. processPeerUpdate("0 3"); // no parameters passed i.e pszNodeUUID..
    4. }
    To copy to clipboard, switch view to plain text mode 

    Same problem.. ocorrs.

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

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    It is a Qt Application, not a console application.
    Add CONFIG+=console to your .pro file, rerun qmake and rebuild the application.

  21. The following user says thank you to wysota for this useful post:

    pytro (14th March 2007)

  22. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    processPeerUpdate("0 3"); // no parameters passed i.e pszNodeUUID..
    [...]
    Same problem.. ocorrs.
    Then the problem might be inside processPeerUpdate(). Could you post its code?

  23. The following user says thank you to jacek for this useful post:

    pytro (9th March 2007)

  24. #16
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: (Callback API) and (Qt - SIGNAL/SLOT)

    The app collapses here:
    Qt Code:
    1. inline const QString operator+(const QString &s1, const char *s2)
    2. { QString t(s1); t += QString::fromAscii(s2); return t; }
    To copy to clipboard, switch view to plain text mode 

    ProcessPeerUpdate()
    Qt Code:
    1. void GuiApp::processPeerUpdate(QString h)
    2. {
    3. QStringList d = h.split(" ");
    4. e = new DataUpdateEvent(d);
    5. qApp->postEvent(this, e);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GuiApp::customEvent(QEvent *e)
    2. {
    3. if ( e->type() == 65432 ) {
    4. DataUpdateEvent* ce = (DataUpdateEvent*)e;
    5. i = ce->data();
    6. }
    7. setValue(i);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class DataUpdateEvent : public QCustomEvent
    2. {
    3. public:
    4. DataUpdateEvent(QStringList i)
    5. : QCustomEvent( 65432 ), n(i) {}
    6.  
    7. QStringList data() { return n; }
    8.  
    9. private:
    10.  
    11. public:
    12. ~DataUpdateEvent(void)
    13. {
    14. }
    15. };
    To copy to clipboard, switch view to plain text mode 

  25. #17
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Problem Solved.. Thanks all

  26. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    Problem Solved..
    What was the problem?

  27. #19
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Sorry for the late feedback.
    Well the problem had ramifications ...
    The listenner (i.e Callback API) wasn't correcty initialized inside Qt App,
    and the last error one was easy.. the "tablewidget update" setText with null values .

    Thanks again.

  28. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Callback API) and (Qt - SIGNAL/SLOT)

    Quote Originally Posted by pytro View Post
    The listenner (i.e Callback API) wasn't correcty initialized inside Qt App,
    and the last error one was easy.. the "tablewidget update" setText with null values .
    I see. In such case valgrind's memcheck might be the right tool to identify the problem.

  29. The following user says thank you to jacek for this useful post:

    pytro (14th March 2007)

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
  •  
Qt is a trademark of The Qt Company.