简体   繁体   English

Qt5:无法将信号连接到插槽

[英]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> 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. 因此,我清理了我的项目, run qmake ,构建了项目……播放它,得到的GUI与以前完全相同,没有新的Menu项。

When App is run, I get the following message> 运行App时,出现以下消息>

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. 我在关于stackoverflow的其他问题上注意到不建议使用connectSlotsByName ,但是我的所有函数和插槽都完全相同,因此它应该像这样工作。

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 在编译时,Qt将ui_mainwindow.h在其新创建的build文件夹中,而不是在项目文件夹中。因此,该应用程序看不到更新的.h

After copying new .h to the project folder, doing qmake and building again, everything looks ok. 将新的.h复制到项目文件夹后,执行qmake并再次构建,一切看起来都很好。

Remove the underscores in the action name. 删除操作名称中的下划线。 And define the slot as: 并将插槽定义为:

void MainWindow::on_actionDownloadFirmwareImage_triggered(bool checked)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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