简体   繁体   中英

Qt5: could not connect signal to slot

I'm trying to upgrade my old Application.. (add it one more function). So, I added one more item in 'File' menu.

<addaction name="actionDownload_Firmware_Image"/>

<action name="actionDownload_Firmware_Image">


<property name="text">
    <string>&amp;Download Firmware Image</string>
   </property>
   <property name="menuRole">
    <enum>QAction::ApplicationSpecificRole</enum>
   </property>
  </action>

Defined my Slot here:

void MainWindow::on_actionDownload_Firmware_Image_triggered()

MainWindow.h>

private slots:
    void on_actionDownload_Firmware_Image_triggered();

So, I clean my project, run qmake , build project... Play it, and I get exactly the same GUI as before, no new Menu item.

When App is run, I get the following message>

QMetaObject::connectSlotsByName: No matching signal for on_actionDownload_Firmware_Image_triggered()

I noticed on other questions on stackoverflow that connectSlotsByName is not recommended for use, but all of my functions and slots are called exactly the same, so it should work like this.

I'm not sure why this is happening, any help is welcome.

Thanks!

The problem is solved!

No coding was needed...

While compiling, Qt puts the ui_mainwindow.h in its newly created build folder, and not in the project folder.. So the app doesn't see the updated .h

After copying new .h to the project folder, doing qmake and building again, everything looks ok.

Remove the underscores in the action name. And define the slot as:

void MainWindow::on_actionDownloadFirmwareImage_triggered(bool checked)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM