Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [UI] Connection between QAction and SLOT
QtWS25 Last Chance

[UI] Connection between QAction and SLOT

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 15.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lowee
    wrote on last edited by
    #1

    Hi everybody,

    I've already made a Qt UI with Qt Designer and I got a menu bar with File menu (New File, Open File, Save File, Quit).

    My wish is to connect the Quit action when its triggered to quit ... I tried the command

    @connect(Ui_MainWindow.actionQuit, SIGNAL(triggered()), this, SLOT(close()));@

    in the constructor of MainWindow but i got this error message :
    @..\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
    ..\mainwindow.cpp:10: error: expected primary-expression before '.' token@

    I don't really understand this error ...

    So I tried with the UI connection action ("go to slot") it works but i just want to know if it's possible to make this connection and if it is possible how (because with the ui connection action, i will get too much functions...) ?

    We are animals that our brain gives us the feeling that we aren't

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      Paste more code. What type is Ui_MainWindow? Where you declare actions? This could be a problem with include(missing include) or not. Hard to say without a context.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        If you want create menu by yourself you must create an action and then bin them with Slot and menu item.

        Something like that:
        @
        void MainWindow::createActions()
        {
        newAction = new QAction(tr("&New"), this);
        newAction->setIcon(QIcon(":/images/new.png"));
        newAction->setShortcut(tr("Ctrl+N"));
        newAction->setStatusTip(tr("Create a new spreadsheet file"));
        connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

        @

        adding menu item
        @
        fileMenu = menuBar()->addMenu(tr("&File"));
        fileMenu->addAction(newAction);
        @

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          but if you want use already created Actions:

          @connect(ui->actionName, SIGNAL(triggered()), this, SLOT(on_triggered()));
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lowee
            wrote on last edited by
            #5

            Thanks a lot qxoz, I'll create the entire interface including the menu item.

            If I have some problems, I'll post them in this post...

            We are animals that our brain gives us the feeling that we aren't

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved