Results 1 to 6 of 6

Thread: how to use menuBar and Action

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default how to use menuBar and Action

    hy,
    how I just said yesterday I'm trying to build my first GUI application. I want my interface to stay very simple with just one button that starts the countdown and then changes into stop to stop the countdown. I wanted to have at the top in the menuBar something called File and if you click on it another menu appears and there is the voice set starting value. until here no problem, but I want to click on set string value and see another window appear, how can I do this? I created another Qt Designer form class, but maybe a Qt Designer form would be enough?

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use menuBar and Action

    Well, it seems that you dont have you ideas very clear. Research about signals and slots (connect), there`s a lot of information over the internet. The idea is that when you trigger an action of your menu something happens, for example a Dialog shows up, that means that the signal trigger () of the action calls the slot showAdialog. Then you may want to return to the view of the mainWindow, so you need to figure out a way to indicate the mainWindow to show, either by finishing the execution of the Dialog or a signal from the dialog telling the mainWindow it has finished.

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

    sax94 (10th February 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use menuBar and Action

    hy,
    I saw on the nokia developer site that to connect a signal to a slot you should use connect(sender, SIGNAL(signal), receiver, SLOT(slot));
    in my case this sould be
    Qt Code:
    1. QObject::connect(ui->actionModifica_valore_iniziale,SIGNAL(triggered()),dialog,SLOT(show()));
    To copy to clipboard, switch view to plain text mode 
    so my menuFile Modifica_valore_iniziale that stands for set value, emits the signall triggered(). in the receiver spot I must put what I want to see wuen the signal is emitted, but if I put dialog Qt tells me that dialog wasn't declared, but if I put ui.menuBar and then I click the action the menuBar appears, same if I put ui.menuFile, the menuFile stays there. so what do I have to do?
    thank's for the help

  5. #4
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use menuBar and Action

    MMM i think you are connecting the objects the wrong way...You have a mainWindow with a menuBar and you want a dialog to pop-up...right?

    So the right thing to connect is this (in the constructor of mainWindow):

    Qt Code:
    1. connect(ui->actionModifica_valore_iniziale,SIGNAL(triggered()),this, SLOT(//this slot shows the dialog));
    To copy to clipboard, switch view to plain text mode 

    then mainWindow has a SLOT called
    //this slot shows the dialog
    that will do something like this:

    Qt Code:
    1. void //this slot shows the dialog{
    2. myDialog *dialog = new myDialog ();
    3. //do something for example:
    4. dialog->setData (ui->labelText->text ()); //you assign data from a label of the mainWindow to the dialog...
    5. dialog->exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    it is important that you understand the concept because this is used like a lot...

    hope it helps!

    PS:- with exec () you assure that the focus is going to return to mainWindow when the dialog closes

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

    sax94 (13th February 2012)

  7. #5
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use menuBar and Action

    hy,
    thank's for yout help, I managed to open the dialog, now In my dialog there is a spinbox, I want that when he closes the dialog, the value in the spinbox to appear in the label in the main window. i write this in the dialog constructor
    Qt Code:
    1. QObject::connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(DisplayData()));
    To copy to clipboard, switch view to plain text mode 
    but in my slot DisplayData() I can't set the label value, this is my code
    Qt Code:
    1. void MainWindow::DisplayData()
    2. {
    3. MainWindow *c;
    4. c->setwhat?
    5. //........
    6. }
    To copy to clipboard, switch view to plain text mode 
    how can I do it?
    Last edited by sax94; 13th February 2012 at 11:10.

  8. #6
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use menuBar and Action

    In that case you have to emit your own signal...you haven`t read the documentation at all right? lol....in your case it would be something like this:

    First you need to connect the accept button from your dialog with a slot of the dialog class, and also create a signal in that class

    signals:
    void dialog_accepted (QString)
    the slot from the dialog needs to be connected to a click event when you create the class (do that)
    Qt Code:
    1. void slot_when_button_clicked (){
    2. //mmm
    3. //yo do staff
    4. // --here comes the important part
    5. emit dialog_accepted (ui->spinbox->currentText()); //look the function of spinbox that returns current value
    6. close ();
    7. }
    To copy to clipboard, switch view to plain text mode 

    then in your main window you connect the dialog signal "dialog_accepted" with a display slot of the mainwin...something like (in mainwindow)

    Qt Code:
    1. connect (dialog, SIGNAL (dialog_accepted (QString)), this, SLOT(display_spin_from_dialog (QString)));
    To copy to clipboard, switch view to plain text mode 

    have a look at signals and slots because if not you are going to come here soon asking for more :P

    hope it helps!

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

    sax94 (13th February 2012)

Similar Threads

  1. How to go to slot of an action on the menubar?
    By Bong.Da.City in forum Newbie
    Replies: 2
    Last Post: 6th September 2010, 11:51
  2. [QT] MenuBar
    By iVo1d in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2010, 13:14
  3. Bar on menubar?
    By zgulser in forum Qt Tools
    Replies: 6
    Last Post: 14th January 2009, 08:07
  4. Using the menubar
    By Steve in forum Newbie
    Replies: 10
    Last Post: 27th February 2006, 15:59
  5. No action checked in an exclusive action group
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 06:19

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.