Results 1 to 6 of 6

Thread: Slots and Connection of Forms...

  1. #1
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Slots and Connection of Forms...

    Hi,

    So I have a standalone application which has a QMainWindow. I created another application which is also a QMainWindow. I tried linking them using a button but it did not work. I then changed the second application to QDialog and then the button worked! But since I changed it from QMainWindow to QDialog, the slots stopped working on the new application (I guess the dialog cannot have many buttons..)

    Anyway, how do I get this working so that the first QMainWindow opens the second QMainWindow or QDialog AND the buttons in the second application still work..?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Slots and Connection of Forms...

    It does not matter if it is a QDialog or a QMainWindow. So can you show us your code which is not working for both solution.

  3. #3
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slots and Connection of Forms...

    First app: MainWin

    Qt Code:
    1. MainWin::MainWin(QWidget*p, Qt::WindowFlags f):QMainWindow(p,f)
    2. {
    3. dSecond = NULL; // QDialog
    4. ui.setupUi(this);
    5. connect(ui.action_Two, SIGNAL(activated()), this, SLOT(two()));
    6. }
    7.  
    8. MainWin::~MainWin()
    9. {
    10. }
    11.  
    12. void MainWin::two()
    13. {
    14. if(!dSecond)
    15. {
    16. dSecond = new QDialog(this);
    17. uiSecond.setupUi(dSecond); //ui::Second uiSecond;
    18. }
    19. dSecond->exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Second app: Second

    Qt Code:
    1. Second::Second(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Second)
    4. {
    5. connect(ui->action_button, SIGNAL(clicked()), this, SLOT(func_clicked()));
    6. }
    7.  
    8. discovery::~discovery()
    9. {
    10. delete ui;
    11. }
    12.  
    13. void discovery::func_clicked()
    14. {
    15. QMessageBox::warning(0,"Test", "Test message. It works!");
    16. }
    To copy to clipboard, switch view to plain text mode 

    This way shows the new app when the menu bar item is clicked, but the new app does not show warning message when button is pressed.

  4. #4
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slots and Connection of Forms...

    in second the SLOT is a
    Qt Code:
    1. void Second::func_clicked()
    To copy to clipboard, switch view to plain text mode 
    and you have a
    Qt Code:
    1. void discovery::func_clicked()
    To copy to clipboard, switch view to plain text mode 
    Maybe the discovery is a relic from the previous implemantation?
    (the same for the destructor. Does it compile???)

    Check this:
    http://www.qtcentre.org/faq.php?faq=qt_signalslot
    Last edited by Rhayader; 20th March 2011 at 01:58.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,554
    Thanks
    13
    Thanked 1,581 Times in 1,510 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slots and Connection of Forms...

    If these two QWidgets are in separate applications, as both the first and third posts both state/imply, then there is no amount of trickery that is going to make a signal in one trigger a slot in the other.

  6. #6
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slots and Connection of Forms...

    Working now!

Similar Threads

  1. Replies: 0
    Last Post: 17th April 2010, 18:13
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  3. Signal-slots connection problem.
    By impeteperry in forum Qt Tools
    Replies: 26
    Last Post: 23rd January 2007, 15:33
  4. Slots connection !
    By agent007se in forum Newbie
    Replies: 6
    Last Post: 25th July 2006, 02:28
  5. howto debug connection of signals and slots?
    By jh in forum Qt Programming
    Replies: 11
    Last Post: 24th February 2006, 10:30

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.