[SOLVED] QMenuBar



  • Hi, I'm trying to figure out why my QMenuBar doesn't work.

    @ WidgetVisible = ui->menuBar->addAction("Add Labels Screen");
    connect(WidgetVisible, SIGNAL(triggered()), this, SLOT(WidgetOn()));@

    then when I click on "Add Labels Screen" it doesn't do anything??

    Thank you for your help,

    mrstarware


  • Moderators

    That snippet of code seems reasonable. Do you get any error message? What does the WidgetOn() slot code look like?



  • Does your console output a message like "no such slot" ?

    I agree with mlong, please show your slot code.



  • Ok I just found the application output. I didn't know it existed. x.x
    Anyway, it says "No such slot MainWindow::WidgetOn()" What would be causing this? the connection is made in MainWindow's constructor?



  • in your mainwindow.h file you should have:
    @
    public slots:
    void WidgetOn();
    @

    And in your mainwindow.cpp your slot should look like:
    @
    void MainWindow::WidgetOn() {
    // code...
    }
    @


  • Moderators

    Also, you want to make sure that your mainwindow.h file contains the Q_OBJECT macro, as well.



  • Oops. Messed up on the definition of "slot". It works now.

    Thanks much.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.