Results 1 to 4 of 4

Thread: signal slot to mainwindow

  1. #1
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default signal slot to mainwindow

    hello.
    I'm read about the behaviour of signal/slot in qt.
    My problem is that i have created a custom widget and the emission of the signal(emit pressed()) is in a custom delegate of my project.
    How i can "take out" the signal for invoke the "pressedButton()" slot that is in the main window?
    i must send the main window pointer(m_pMainWindow) and transport it to the delegate?

    where i can do:
    Qt Code:
    1. connect(this, SIGNAL(pressed()),
    2. m_pMainWindow, SLOT(prssedButton())));
    To copy to clipboard, switch view to plain text mode 

    is correct?
    thanks.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal slot to mainwindow

    that is bad design. Normally you should do it the other way around:


    Qt Code:
    1. connect(my_custom_widget, SIGNAL(pressed()),
    2. this, SLOT(pressedButton())));
    To copy to clipboard, switch view to plain text mode 


    This is so that clients of the signal do not have to be known to the emitter. This maintains dependency injection principles.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default Re: signal slot to mainwindow

    thanks, another thing :
    I have this code in the main function , but the "connect" function works only if the class inherits from QOBject(is correct?) and the main function is not a class function.
    then I have a openglwidget that inherits from qobject and the opengl code that don't inherits from qobject how i can manage all the signals and slots?
    I must create a central class(that inherits from QObject) that works as a bridge from qt to opengl and other possible subsystems?
    thanks.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal slot to mainwindow

    you can just use


    QObject::connect(qobjectPtr1, SIGNAL(some_signal()), qobjectPtr2, SLOT(some_slot()));
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 8
    Last Post: 7th November 2012, 14:10
  2. Replies: 2
    Last Post: 3rd May 2011, 20:22
  3. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 10:00
  4. Updating MainWindow from slot
    By Barry79 in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 15:44
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.