在Visual Studio 2015中重用cmake构建的QT项目:“ connectSlotsByName:无匹配信号”

时间:2018-08-15 11:43:53

标签: c++ visual-studio qt visual-studio-2015 code-reuse

如上所述,我的任务是更改使用QT 5.7的现有Visual Studio项目的代码。 在我之前从事此工作的学生不幸地用我完全不熟悉的cmake构建了他的项目,但不幸的是,我绝对没有时间参与其中。

我的第一个尝试是建立一个新的VS项目,将所有必要的源文件和QT文件粘贴到其中。 这导致了几个问题,其中之一是我必须在所有Q类中删除,保存和重写<!DOCTYPE html> <html> <head> <title>HOME</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="../css/home.css"> </head> <body class=background> <div class="btn-container"> <button class="button login">LOGIN</button> </div> <div class="btn-container"> <button class="button register">REGISTER</button> </div> </body> </html>

这告诉我,实际的工作流程从一开始就在破坏项目。

关于这一点,我的前任使用Q_OBJECT连接Gui对象(如Buttons)的信号和插槽。调试时得到

QMetaObject::connectSlotsByName

对于GUI中所有现有的QWidget-Childs。

这似乎很奇怪,因为此类按钮等的信号必须以moc代码存在(当然存在相应的插槽),对吗?

项目中存在大量的Gui元素,因此我宁愿不要对每个元素都使用connect。

问题:

1。)是否有建议的工作流程,该工作流程使人脚射门的频率降低? 2.)为了使Qt的元对象编译器能够创建QMetaObject::connectSlotsByName: No matching signal for on_[some Gui Obejct]_clicked() ui_*.h,需要moc_*.cpp*.ui和潜力资源文件,对吗? 3.)该项目最初由cmake构建的事实在多大程度上会影响Qt-meta编译?

非常感谢您

编辑: QMainWindow-Class *.qrc的其他信息和代码示例。 我添加了Navigation_Gui行,这会产生过多的违规行为,我认为不应该这样做。

connect

标题

Navigation_Gui::Navigation_Gui(QWidget *parent)
: QWidget(parent){

this->Storage = new ThreadStorage();                            
this->CamPtr = new CamBar(this->Storage);   
this->NavPtr = new Navigation(this->CamPtr, this->Storage);

ui.setupUi(this);

this->getRegPoints = false;
this->Storage->Log << "Main Gui initialized" << endl;

connect(this->ui.pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); }

这是生成的Ui头

#ifndef NAVIGATION_GUI_H
#define NAVIGATION_GUI_H


#include <QWidget>
#include "ui_navigation_gui.h"
#include <windows.h>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include "vtkMatrix4x4.h"
#include <vector>
#include "ThreadStorage.h"

class CamBar;       //forward deklaration  
class Navigation;   //forward declaration 
class ThreadStorage;    //forward declaration


class Navigation_Gui : public QWidget
{
    Q_OBJECT

public:
    Navigation_Gui(QWidget *parent = 0);
    ~Navigation_Gui();

    //! true if Button GetRegPoints is pressed.
    bool getRegPoints;

    public slots:
    void on_pushButton_clicked();

private:
    Ui::Navigation_GuiClass ui;
    //! initial CameraPointer
    CamBar* CamPtr;
    //! initial NavigationPointer
    Navigation* NavPtr;
    //! initial LogPointer
    ThreadStorage* Storage;


    private slots:
    // private slots for Gui events
    void on_ConnectButton_clicked();
    void on_RegPointButton_clicked();
    //void on_TrackingButton_clicked();
    void on_QuitButton_clicked();
    void on_NewTrackingButton_clicked();
    void on_getLocatorButton_clicked();
    void on_MHHAbout_clicked();

};
#endif // NAVIGATION_GUI_H

当我将上述构造函数中的#ifndef UI_NAVIGATION_GUI_H #define UI_NAVIGATION_GUI_H #include <QtCore/QVariant> #include <QtWidgets/QAction> #include <QtWidgets/QApplication> #include <QtWidgets/QButtonGroup> #include <QtWidgets/QGridLayout> #include <QtWidgets/QHeaderView> #include <QtWidgets/QPushButton> #include <QtWidgets/QSpacerItem> #include <QtWidgets/QVBoxLayout> #include <QtWidgets/QWidget> QT_BEGIN_NAMESPACE class Ui_Navigation_GuiClass { public: QGridLayout *gridLayout; QVBoxLayout *verticalLayout; QSpacerItem *verticalSpacer; QPushButton *ConnectButton; QSpacerItem *verticalSpacer_2; QPushButton *getLocatorButton; QSpacerItem *verticalSpacer_7; QPushButton *RegPointButton; QSpacerItem *verticalSpacer_3; QPushButton *NewTrackingButton; QSpacerItem *verticalSpacer_4; QSpacerItem *verticalSpacer_5; QPushButton *QuitButton; QSpacerItem *verticalSpacer_6; QPushButton *pushButton; QPushButton *MHHAbout; void setupUi(QWidget *Navigation_GuiClass) { if (Navigation_GuiClass->objectName().isEmpty()) Navigation_GuiClass->setObjectName(QStringLiteral("Navigation_GuiClass")); Navigation_GuiClass->setWindowModality(Qt::WindowModal); Navigation_GuiClass->resize(358, 500); QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(Navigation_GuiClass->sizePolicy().hasHeightForWidth()); Navigation_GuiClass->setSizePolicy(sizePolicy); Navigation_GuiClass->setMinimumSize(QSize(358, 458)); Navigation_GuiClass->setMaximumSize(QSize(358, 500)); gridLayout = new QGridLayout(Navigation_GuiClass); gridLayout->setSpacing(6); gridLayout->setContentsMargins(11, 11, 11, 11); gridLayout->setObjectName(QStringLiteral("gridLayout")); verticalLayout = new QVBoxLayout(); verticalLayout->setSpacing(6); verticalLayout->setObjectName(QStringLiteral("verticalLayout")); verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer); ConnectButton = new QPushButton(Navigation_GuiClass); ConnectButton->setObjectName(QStringLiteral("ConnectButton")); QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(1); sizePolicy1.setHeightForWidth(ConnectButton->sizePolicy().hasHeightForWidth()); ConnectButton->setSizePolicy(sizePolicy1); ConnectButton->setMinimumSize(QSize(0, 68)); QFont font; font.setPointSize(14); ConnectButton->setFont(font); verticalLayout->addWidget(ConnectButton); verticalSpacer_2 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_2); getLocatorButton = new QPushButton(Navigation_GuiClass); getLocatorButton->setObjectName(QStringLiteral("getLocatorButton")); sizePolicy1.setHeightForWidth(getLocatorButton->sizePolicy().hasHeightForWidth()); getLocatorButton->setSizePolicy(sizePolicy1); getLocatorButton->setMinimumSize(QSize(0, 68)); getLocatorButton->setFont(font); verticalLayout->addWidget(getLocatorButton); verticalSpacer_7 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_7); RegPointButton = new QPushButton(Navigation_GuiClass); RegPointButton->setObjectName(QStringLiteral("RegPointButton")); RegPointButton->setEnabled(false); sizePolicy1.setHeightForWidth(RegPointButton->sizePolicy().hasHeightForWidth()); RegPointButton->setSizePolicy(sizePolicy1); RegPointButton->setMinimumSize(QSize(0, 68)); RegPointButton->setFont(font); verticalLayout->addWidget(RegPointButton); verticalSpacer_3 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_3); NewTrackingButton = new QPushButton(Navigation_GuiClass); NewTrackingButton->setObjectName(QStringLiteral("NewTrackingButton")); NewTrackingButton->setEnabled(false); sizePolicy1.setHeightForWidth(NewTrackingButton->sizePolicy().hasHeightForWidth()); NewTrackingButton->setSizePolicy(sizePolicy1); NewTrackingButton->setMinimumSize(QSize(0, 68)); NewTrackingButton->setFont(font); verticalLayout->addWidget(NewTrackingButton); verticalSpacer_4 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_4); verticalSpacer_5 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_5); QuitButton = new QPushButton(Navigation_GuiClass); QuitButton->setObjectName(QStringLiteral("QuitButton")); sizePolicy1.setHeightForWidth(QuitButton->sizePolicy().hasHeightForWidth()); QuitButton->setSizePolicy(sizePolicy1); QuitButton->setMinimumSize(QSize(0, 68)); QuitButton->setFont(font); verticalLayout->addWidget(QuitButton); verticalSpacer_6 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout->addItem(verticalSpacer_6); pushButton = new QPushButton(Navigation_GuiClass); pushButton->setObjectName(QStringLiteral("pushButton")); verticalLayout->addWidget(pushButton); MHHAbout = new QPushButton(Navigation_GuiClass); MHHAbout->setObjectName(QStringLiteral("MHHAbout")); QIcon icon; icon.addFile(QStringLiteral(":/MainWindow/Resources/60px.png"), QSize(), QIcon::Normal, QIcon::Off); MHHAbout->setIcon(icon); MHHAbout->setIconSize(QSize(174, 60)); verticalLayout->addWidget(MHHAbout); gridLayout->addLayout(verticalLayout, 0, 0, 1, 1); retranslateUi(Navigation_GuiClass); QMetaObject::connectSlotsByName(Navigation_GuiClass); } // setupUi void retranslateUi(QWidget *Navigation_GuiClass) { Navigation_GuiClass->setWindowTitle(QApplication::translate("Navigation_GuiClass", "Main Menu - Navigation (CamBar)", 0)); ConnectButton->setText(QApplication::translate("Navigation_GuiClass", "Connect", 0)); getLocatorButton->setText(QApplication::translate("Navigation_GuiClass", "Locator Editor", 0)); RegPointButton->setText(QApplication::translate("Navigation_GuiClass", "Get Registration Points", 0)); NewTrackingButton->setText(QApplication::translate("Navigation_GuiClass", "Tracking", 0)); QuitButton->setText(QApplication::translate("Navigation_GuiClass", "Quit", 0)); pushButton->setText(QApplication::translate("Navigation_GuiClass", "PushButton", 0)); MHHAbout->setText(QString()); } // retranslateUi }; namespace Ui { class Navigation_GuiClass: public Ui_Navigation_GuiClass {}; } // namespace Ui QT_END_NAMESPACE #endif 行更改为

connect

我明白了

connect(this->ui.pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));

这也很奇怪。

0 个答案:

没有答案