Results 1 to 20 of 20

Thread: newbe question about signals / slots

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    Sorry - no matches. Please try some different terms.

    That comes when i use your link - http://www.qtcentre.org/forum/search.php?searchid=61976


    ??? STRANGE ???


    Instead I read and try to understand this thread: http://www.qtcentre.org/forum/f-qt-p...slot-5998.html


    Best Regards...
    Last edited by Walsi; 20th April 2007 at 06:30.

  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: newbe question about signals / slots

    No, it's not strange. Search results are cached for a limited period of time and it just fell out of cache. It's better to give the URL including search terms instead of the result id. I guess the term was probably "callback".

  3. #3
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    wysota wrote in this thread:

    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.
    Is that the right way to handle my problem?

  4. #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: newbe question about signals / slots

    I have no idea, because I don't know what your problem is Looks like it's something different than what the quoted sentence was about.

  5. #5
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    I think it is the same, I want to emit a signal, when callback function from my SIP client (non Qt, only C++) is called.

    How can I do this?

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    In the Qt app, the callback will be a static function. Given this, you cannot emit a signal from this function when it is called ( it is static, non-QObject ), but you can call a function from the interface ( you will have to make possible the access to the main window or another widget from this callback ). Another solution would be QApplication:: postEvent to post an event that when received by the app will answer the phone or whatever....

    Regards
    Last edited by marcel; 20th April 2007 at 07:57.

  7. #7
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    Okay that sounds good! I try if understand it in the right way:

    I call a function in the callback function from the PJSIP (on_incoming_Call);
    This function has access to any Widget or to the main window of Qt;
    And in this Function I emit a signal;

    Have a look at my Pseudo Source Code

    uscsippart.cpp: This is the file where the Callbackfunctions of PJSIP are. This callback function is called when someona calls me. And in this function a call another function (incomingCallFunc).

    Qt Code:
    1. /* Callback called by the library upon receiving incoming call */
    2. static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
    3. pjsip_rx_data *rdata)
    4. {
    5. pjsua_call_info ci;
    6.  
    7. PJ_UNUSED_ARG(acc_id);
    8. PJ_UNUSED_ARG(rdata);
    9.  
    10. pjsua_call_get_info(call_id, &ci);
    11.  
    12. PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!",
    13. (int)ci.remote_info.slen,
    14. ci.remote_info.ptr));
    15.  
    16. /* Automatically answer incoming calls with 200/OK */
    17. pjsua_call_answer(call_id, 200, NULL, NULL);
    18. incomingCallFunc();
    19. }
    To copy to clipboard, switch view to plain text mode 

    uscinterface.h: here is a "DummyObject" which should has a signal and further here is the prototyp of the function incomingCallFunc();

    Qt Code:
    1. #ifndef INTERFACE_H
    2. #define INTERFACE_H
    3.  
    4. #include <QObject>
    5.  
    6. class IncomingCall : public QObject
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. IncomingCall(QObject *parent = 0);
    12.  
    13.  
    14. signals:
    15. void incomingCallsignal();
    16. };
    17.  
    18. void incomingCallFunc(void);
    19. #endif
    To copy to clipboard, switch view to plain text mode 

    uscinterface.cpp: looks like this!

    Qt Code:
    1. #include "uscinterface.h"
    2.  
    3. IncomingCall::IncomingCall (QObject *parent)
    4. : QObject(parent)
    5. {
    6. }
    7.  
    8. void incomingCallFunc()
    9. {
    10. // QT Code to emit a signal
    11. }
    To copy to clipboard, switch view to plain text mode 

    uscgui.h:

    Qt Code:
    1. #ifndef USCGUI_H
    2. #define USCGUI_H
    3.  
    4. #include <QWidget>
    5.  
    6. class QLabel;
    7.  
    8. class UscGuiES01 : public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. UscGuiES01(QWidget *parent = 0);
    14.  
    15. signals:
    16.  
    17. private slots:
    18.  
    19. void makeCall();
    20. void incomingCall();
    21. private:
    22. QLabel *statusLabel;
    23. QPushButton *acceptButton;
    24. QPushButton *hangupButton;
    25. QPushButton *dialButton;
    26. };
    27.  
    28. class UscStatusDisplay : public QWidget
    29. {
    30. Q_OBJECT
    31.  
    32. public:
    33. UscStatusDisplay(QWidget *parent = 0);
    34. };
    35. #endif
    To copy to clipboard, switch view to plain text mode 

    and now uscgui.cpp: Here I generate my GUI I connect Signals and Slots.

    Qt Code:
    1. #include <pjlib.h>
    2. #include <pjlib-util.h>
    3. #include <pjmedia.h>
    4. #include <pjmedia-codec.h>
    5. #include <pjsip.h>
    6. #include <pjsip_simple.h>
    7. #include <pjsip_ua.h>
    8. #include <pjsua-lib/pjsua.h>
    9.  
    10. #include <QtGui>
    11. #include "uscgui.h"
    12. #include "uscinterface.h"
    13.  
    14. UscGuiES01::UscGuiES01(QWidget *parent)
    15. : QWidget(parent)
    16. {
    17.  
    18. statusLabel = new QLabel(tr("???"));
    19.  
    20. dialButton = new QPushButton(tr("Dial"));
    21.  
    22. acceptButton = new QPushButton(tr("Accept"));
    23. acceptButton->setDefault(true);
    24. acceptButton->setEnabled(false);
    25.  
    26. hangupButton = new QPushButton(tr("Hang Up"));
    27. hangupButton->setEnabled(false);
    28.  
    29. UscStatusDisplay *uscGuiStatusDisplay = new UscStatusDisplay;
    30. IncomingCall *incomingCall = new IncomingCall;
    31.  
    32.  
    33. /*
    34.  Insert here the connections for the Signals and Slots
    35.  System
    36. */
    37.  
    38. connect(dialButton, SIGNAL(clicked()),
    39. this, SLOT(makeCall()));
    40.  
    41. connect(incomingCall, SIGNAL(incomingCallsignal()),
    42. this, SLOT(incomingCall()));
    43.  
    44. QHBoxLayout *bottomLayout = new QHBoxLayout;
    45. bottomLayout->addWidget(dialButton);
    46. bottomLayout->addWidget(acceptButton);
    47. bottomLayout->addWidget(hangupButton);
    48.  
    49. QHBoxLayout *topLayout = new QHBoxLayout;
    50. topLayout->addWidget(statusLabel);
    51. topLayout->addWidget(uscGuiStatusDisplay);
    52.  
    53. QVBoxLayout *mainLayout = new QVBoxLayout;
    54. mainLayout->addLayout(topLayout);
    55. mainLayout->addLayout(bottomLayout);
    56. setLayout(mainLayout);
    57.  
    58. setWindowTitle(tr("Universal SIP Client"));
    59.  
    60. emit
    61. }
    62. /*
    63.  Insert here the SLOT Functions
    64. */
    65.  
    66. void UscGuiES01::makeCall()
    67. {
    68. pj_str_t uri = pj_str("sip:nb100149@10.17.1.17");
    69. pjsua_call_make_call(0, &uri, 0, NULL, NULL, NULL);
    70. }
    71.  
    72. void UscGuiES01::incomingCall()
    73. {
    74. acceptButton->setEnabled(true);
    75. hangupButton->setEnabled(true);
    76. }
    77.  
    78. UscStatusDisplay::UscStatusDisplay(QWidget *parent)
    79. : QWidget(parent)
    80. {
    81. setPalette(QPalette(QColor(Qt::green)));
    82. setAutoFillBackground(true);
    83. }
    To copy to clipboard, switch view to plain text mode 


    Now I want to emit the signal of the class Incomingcall(uscinterface.h) by the function incomingCallFunc() in uscinterface.cpp. but I don't now how??

    Or, another possibility, I want to set in this function the Buttons (accept, hangup) enabled and leave the signals and slots out for this part.

    So, how can I implement that this function has access to the widget (uscgui.cpp)


    I have no idea?

    Best Regards...

  8. #8
    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: newbe question about signals / slots

    I think your situation is completely different. You just want to access a method (emit a signal) from an object you don't have a pointer to. Just make the pointer available somewhere so that the callback can access it and that's it. You don't need any special external or additional objects or any other kind of special treatment.

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    Yes, juts call the slot from the interface in incomingCallFunc. No need to emit the signal. Make your main window available in incomingCallFunc and simply call the slot (which now doesn't necessarily needs to be a slot ).

    Regards

  10. #10
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    OMG

    That really sounds very easy for me. But i think it isn't as easy for me to implement.

    Okay, let me try:

    I generate a pointer which points to my object usc_gui. This object is created in main.

    main.cpp

    Qt Code:
    1. #include <pjlib.h>
    2. #include <pjlib-util.h>
    3. #include <pjmedia.h>
    4. #include <pjmedia-codec.h>
    5. #include <pjsip.h>
    6. #include <pjsip_simple.h>
    7. #include <pjsip_ua.h>
    8. #include <pjsua-lib/pjsua.h>
    9.  
    10. #include <QApplication>
    11.  
    12. #include "uscsippart.h"
    13. #include "uscgui.h"
    14. #include "uscinterface.h"
    15.  
    16. int main(int argc, char *argv[])
    17. {
    18. init_sip();
    19.  
    20. QApplication uscguiapp(argc, argv);
    21. UscGuiES01 usc_gui;
    22. usc_gui.show();
    23.  
    24. return uscguiapp.exec();
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

    Via the parameters I give the callback function the pointer and in the function I can do anything with the object.

    For example:
    Qt Code:
    1. void incomingCallFunc(Usc_Gui_ES01 *to_usc_gui)
    2. {
    3. *to_usc_gui.acceptButton->setEnabled(true);
    4. *to_usc_gui.hangupButton->setEnabled(true);
    5. }
    To copy to clipboard, switch view to plain text mode 

    But where I call this function, the pointer also must be known there?

    Qt Code:
    1. incomingCallFunc(&to_usc_gui);
    To copy to clipboard, switch view to plain text mode 

    Where and how must I define and/or declarate the pointer that it works?

    Best Regards,...

  11. #11
    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: newbe question about signals / slots

    You should really learn a bit of C++... Your problem is strictly programming language related.

  12. #12
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: newbe question about signals / slots

    Okay!!

    Many thanks to you!!

    I will learn C++!!!

  13. #13
    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: newbe question about signals / slots

    Please read about scopes and declarations of external variables. This should allow you to solve the problem yourself.

Similar Threads

  1. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 00:24
  2. Nested signals and slots
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 09:47
  3. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12
  4. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 22:09
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

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.