新手提问,编译时错误请大家帮忙看下。谢谢了

Tommy 2009-12-23 11:20:30
这是头文件
#include "QDialog"
#include "GoToCellDialog.h"
class MyDiaglo : public QDialog , public Ui::GoToCellDiaglo
{
Q_OBJECT
public:
MyDiaglo(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};


源文件
#include "MyDiaglo.h"
#include "QtGui"

MyDiaglo::MyDiaglo(QWidget *parent)
:QDialog(parent)
{
setupUi(this);
RegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(pushButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(pushButton_2 , SIGNAL(clicked()) , this , SLOT(reject()));
}


void MyDiaglo::on_lineEdit_textChanged()
{
pushButton->setEnabled(lineEdit->hasAcceptableInput());
}


编译时出的错误是:
1>------ 已启动生成: 项目: QT-test, 配置: Release Win32 ------
1>正在链接...
1>MyDiaglo.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall MyDiaglo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyDiaglo@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>MyDiaglo.obj : error LNK2001: 无法解析的外部符号 "public: virtual void * __thiscall MyDiaglo::qt_metacast(char const *)" (?qt_metacast@MyDiaglo@@UAEPAXPBD@Z)
1>MyDiaglo.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall MyDiaglo::metaObject(void)const " (?metaObject@MyDiaglo@@UBEPBUQMetaObject@@XZ)
1>C:\Users\熊猫\Documents\Visual Studio 2005\Projects\QT-test\Release\QT-test.exe : fatal error LNK1120: 3 个无法解析的外部命令
1>生成日志保存在“file://c:\Users\熊猫\Documents\Visual Studio 2005\Projects\QT-test\QT-test\Release\BuildLog.htm”
1>QT-test - 4 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========





//如果把以下代码注释掉就能正常编译了。
MyDiaglo::MyDiaglo(QWidget *parent)
:QDialog(parent)
{
setupUi(this);
RegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(pushButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(pushButton_2 , SIGNAL(clicked()) , this , SLOT(reject()));
}


小弟初学QT,请哪位大虾指点下。。
...全文
445 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tingsking18 2009-12-28
  • 打赏
  • 举报
回复
看看手册
或者是找本Qt入门的书看看。
Tommy 2009-12-28
  • 打赏
  • 举报
回复
恩,我确实没有执行过 qmake, 随便在请教下:qmake是个控制台命令吧、? 那我该怎么使用 qmake,让我的程序可以正常编译过啊。我在vs2005下面建立的工程。。
tingsking18 2009-12-28
  • 打赏
  • 举报
回复
qt_metacall
是moc的问题。
估计是添加了Q_OBJECT之后没有执行qmake
gemfield 2009-12-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 rbagglo 的回复:]
MyDiaglo::MyDiaglo(QWidget *parent)
:QDialog(parent)
{
setupUi(this);
RegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));

}
[/Quote]
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");

*******************************MyDiaglo.h**************************

#ifndef MYDIAGLO_H
#define MYDIAGLO_H
#include "QDialog"
#include "ui_GoToCellDialog.h"
class MyDiaglo : public QDialog , public Ui_Dialog
{
Q_OBJECT
public:
MyDiaglo(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};
#endif // MYDIAGLO_H
***************************************************************************
Tommy 2009-12-26
  • 打赏
  • 举报
回复
随便还问个问题,是不是要经常在控制台下,用命令来生成一些文件哦。
Tommy 2009-12-25
  • 打赏
  • 举报
回复
凡是包含Q_OBJECT 的头文件必须moc一下的。
是什么意思哦?初学QT, 懂的东西太少了。。。
Tommy 2009-12-25
  • 打赏
  • 举报
回复
class MyDiaglo : public QDialog , public Ui::GoToCellDiaglo
{
Q_OBJECT
public:
MyDiaglo(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};

这个部分是自己写的。


#include "GoToCellDialog.h" 是uic -o GoToCellDiaglo .h GoToCellDiaglo .ui 产生的.h文件


/********************************************************************************
** Form generated from reading ui file 'GoToCellDialog.ui'
**
** Created: Thu Dec 17 13:44:09 2009
** by: Qt User Interface Compiler version 4.5.3
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/

#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_GoToCellDiaglo
{
public:
QWidget *layoutWidget;
QHBoxLayout *horizontalLayout;
QLabel *label;
QLineEdit *lineEdit;
QWidget *layoutWidget1;
QHBoxLayout *horizontalLayout_2;
QPushButton *pushButton;
QPushButton *pushButton_2;

void setupUi(QWidget *GoToCellDiaglo)
{
if (GoToCellDiaglo->objectName().isEmpty())
GoToCellDiaglo->setObjectName(QString::fromUtf8("GoToCellDiaglo"));
GoToCellDiaglo->resize(400, 300);
layoutWidget = new QWidget(GoToCellDiaglo);
layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
layoutWidget->setGeometry(QRect(80, 90, 219, 23));
horizontalLayout = new QHBoxLayout(layoutWidget);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
horizontalLayout->setContentsMargins(0, 0, 0, 0);
label = new QLabel(layoutWidget);
label->setObjectName(QString::fromUtf8("label"));

horizontalLayout->addWidget(label);

lineEdit = new QLineEdit(layoutWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));

horizontalLayout->addWidget(lineEdit);

layoutWidget1 = new QWidget(GoToCellDiaglo);
layoutWidget1->setObjectName(QString::fromUtf8("layoutWidget1"));
layoutWidget1->setGeometry(QRect(140, 140, 160, 27));
horizontalLayout_2 = new QHBoxLayout(layoutWidget1);
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
pushButton = new QPushButton(layoutWidget1);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setDefault(true);

horizontalLayout_2->addWidget(pushButton);

pushButton_2 = new QPushButton(layoutWidget1);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));

horizontalLayout_2->addWidget(pushButton_2);

QWidget::setTabOrder(pushButton, lineEdit);
QWidget::setTabOrder(lineEdit, pushButton_2);

retranslateUi(GoToCellDiaglo);

QMetaObject::connectSlotsByName(GoToCellDiaglo);
} // setupUi

void retranslateUi(QWidget *GoToCellDiaglo)
{
GoToCellDiaglo->setWindowTitle(QApplication::translate("GoToCellDiaglo", "Form", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("GoToCellDiaglo", "Cell Location", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("GoToCellDiaglo", "OK", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("GoToCellDiaglo", "Cancel", 0, QApplication::UnicodeUTF8));
Q_UNUSED(GoToCellDiaglo);
} // retranslateUi

};

namespace Ui {
class GoToCellDiaglo: public Ui_GoToCellDiaglo {};
} // namespace Ui

QT_END_NAMESPACE

#endif // GOTOCELLDIALOG_H
chenfeng2002 2009-12-25
  • 打赏
  • 举报
回复
class MyDiaglo : public QDialog , public Ui::GoToCellDiaglo
{
Q_OBJECT
public:
MyDiaglo(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};

这个结构是自动生成的吗?
在qtcreator生成的不是这样,Ui::GoToCellDiaglo作为组合成员,而不是继承的父类,看下面:

/* 头文件 */

namespace Ui {
class MyDiaglo;
}

class MyDiaglo : public QDialog
{
Q_OBJECT
public:
MyDiaglo(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();

private:

Ui::GoToCellDiaglo
};

/* cpp 文件 */
MyDiaglo::MyDiaglo(QWidget *parent)
:QDialog(parent),ui(new Ui::GoToCellDiaglo)
{
setupUi(this);

/* 添加自己代码*/

}
Tommy 2009-12-24
  • 打赏
  • 举报
回复
Ui::GoToCellDiaglo 是用designer生成的GoToCellDialog.ui,然后通过uic -o GoToCellDiaglo .h GoToCellDiaglo .ui 产生的.h文件(这个地方只产生了.h,没有.lib文件啊?),在把这个.h文件在目前这个工程中派生的?

netlib 2009-12-24
  • 打赏
  • 举报
回复
MyDiaglo::qt_metacall应该是父类Ui::GoToCellDiaglo 中的函数吧?

你要引用含有Ui::GoToCellDiaglo的lib
goodname 2009-12-24
  • 打赏
  • 举报
回复
凡是包含Q_OBJECT 的头文件必须moc一下的。

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧