我的設置如下:創建QT UI的多個選項卡和初始組合框
main.cpp
projectQt.cpp
projectQt.h
tab1.h
tab1.cpp
tab2.h
tab2.cpp
projectQt.ui
ui_projectQt.h
我想創建一個UI文件的項目。在Ui文件中,我有三個組合框和兩個應用按鈕,並且在tab1.cpp和tab2.cpp中,我想添加組合框的初始項目。如果用戶單擊其中一個應用按鈕,請運行「OnBtnApplyClicked」方法。
但是我得到這個錯誤:
錯誤是
projectQt.obj : error LNK2019: unresolved external symbol "public: __thiscall Ctab1::~Ctab1(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall ProjectQt::ProjectQt(class QWidget *)" ([email protected]@[email protected]@@@Z)
C:\output\Deneme\Qt\Win32\Debug\\projectQt.exe : fatal error LNK1120: 1 unresolved externals
的main.cpp
#include "projectQt.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ProjectQt w;
w.show();
return a.exec();
}
projectQt.ui文件:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectQtClass</class>
<widget class="QMainWindow" name="ProjectQtClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>900</height>
</rect>
</property>
<property name="windowTitle">
<string>ProjectQt</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>800</width>
<height>800</height>
</rect>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="IDC_FORM_TAB_1">
<attribute name="title">
<string>M001</string>
</attribute>
<widget class="QLabel" name="IDC_LBL_1_0">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>124</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>COMBO1</string>
</property>
</widget>
<widget class="QComboBox" name="IDC_CMB_1_0">
<property name="geometry">
<rect>
<x>120</x>
<y>40</y>
<width>69</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QComboBox" name="IDC_CMB_1_1">
<property name="geometry">
<rect>
<x>120</x>
<y>90</y>
<width>69</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="IDC_BTN_1_Apply">
<property name="geometry">
<rect>
<x>180</x>
<y>174</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QLabel" name="IDC_LBL_1_1">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>124</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>COMBO2</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="IDC_FORM_TAB_2">
<attribute name="title">
<string>M002</string>
</attribute>
<widget class="QLabel" name="IDC_LBL_2_0">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>104</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>COMBO3</string>
</property>
</widget>
<widget class="QComboBox" name="IDC_CMB_2_0">
<property name="geometry">
<rect>
<x>100</x>
<y>30</y>
<width>69</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="IDC_BTN_2_Apply">
<property name="geometry">
<rect>
<x>100</x>
<y>70</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="projectQt.qrc"/>
</resources>
<connections/>
</ui>
projectQt.cpp文件:
#include "projectQt.h"
#include "tab1.h"
#include "tab2.h"
#include "ui_projectQt.h"
ProjectQt::ProjectQt(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
Ctab1 ctab11;
Ctab1 ctab22;
ctab11.initGUI();
ctab22.initGUI();
connect(ui.IDC_BTN_1_Apply,SIGNAL(clicked()),this,SLOT(Ctab1::OnBtnApplyClicked()));
connect(ui.IDC_BTN_2_Apply,SIGNAL(clicked()),this,SLOT(Ctab2::OnBtnApplyClicked()));
}
ProjectQt::~ProjectQt()
{
}
projectQt.h文件:
#ifndef projectQt_H
#define projectQt_H
#include <QtWidgets/QMainWindow>
#include "ui_projectQt.h"
#include "tab1.h"
#include "tab2.h"
class ProjectQt : public QMainWindow
{
Q_OBJECT
public:
ProjectQt(QWidget *parent = 0);
~ProjectQt();
//private:
Ui::ProjectQtClass ui;
};
#endif // projectQt_H
tab1.h文件:
#pragma once
#include <string>
#include "projectQt.h"
#include "ui_projectQt.h"
class Ctab1
{
public:
Ctab1(void);
~Ctab1(void);
public slots:
void setEvents();
void initGUI();
void OnBtnApplyClicked();
//private:
//Ui::ProjectQtClass *ui;
};
tab1.cpp文件:
#include "projectQt.h"
#include "tab1.h"
#include <QTextStream>
#include "ui_projectQt.h"
Ctab1::Ctab1(void)
{
}
void Ctab1::initGUI(){
Ui::ProjectQtClass uimain;
uimain.IDC_CMB_1_0->addItem("1100");
uimain.IDC_CMB_1_0->addItem("1101");
uimain.IDC_CMB_1_1->addItem("1200");
uimain.IDC_CMB_1_1->addItem("1201");
}
void Ctab1::OnBtnApplyClicked(){
}
tab2.h文件:
#pragma once
#include <string>
#include "projectQt.h"
#include "ui_projectQt.h"
class Ctab2
{
public:
Ctab2(void);
~Ctab2(void);
public slots:
void setEvents();
void initGUI();
void OnBtnApplyClicked();
//private:
//Ui::ProjectQtClass *ui;
};
tab2.cpp文件:
#include "projectQt.h"
#include "tab2.h"
#include <QTextStream>
#include "ui_projectQt.h"
Ctab2::Ctab2(void)
{
}
void Ctab2::initGUI(){
Ui::ProjectQtClass uimain;
uimain.IDC_CMB_2_0->addItem("2000");
uimain.IDC_CMB_2_0->addItem("2001");
}
void Ctab2::OnBtnApplyClicked(){
}
你不會指定正是你有什麼樣的錯誤。 – eraxillan
我添加錯誤... – CiTi
謝謝。現在,請查看下面的@RobbieE的答案,我認爲這有助於解決問題。 – eraxillan