我刚刚接受了Qt的统计。这是一本书的例子。 我试图将代码与书中的代码进行比较。看起来很相似。
你能帮帮我吗?
NetBeans显示如下:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE=/C/Qt/4.8.4/bin/qmake.exe SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Documents and Settings/Deloitte/��� ���������/NetBeansProjects/HelloWorld1'
/C/Qt/4.8.4/bin/qmake.exe VPATH=. -spec win32-g++ -o qttmp-Debug.mk nbproject/qt-Debug.pro
mv -f qttmp-Debug.mk nbproject/qt-Debug.mk
"/usr/bin/make" -f nbproject/qt-Debug.mk dist/Debug/MinGW_Qt-Windows/HelloWorld1.exe
make[2]: Entering directory `/c/Documents and Settings/Deloitte/��� ���������/NetBeansProjects/HelloWorld1'
g++ -mthreads -Wl,-subsystem,windows -o dist/Debug/MinGW_Qt-Windows/HelloWorld1.exe build/Debug/MinGW_Qt-Windows/main.o build/Debug/MinGW_Qt-Windows/moc_Counter.o -L'c:/Qt/4.8.4/lib' -lmingw32 -lqtmaind build/Debug/MinGW_Qt-Windows/HelloWorld1_resource_res.o -lQtGuid4 -lQtCored4
build/Debug/MinGW_Qt-Windows/main.o: In function `Z5qMainiPPc':
C:\Documents and Settings\Deloitte\��� ���������\NetBeansProjects\HelloWorld1/main.cpp:16: undefined reference to `Counter::Counter()'
build/Debug/MinGW_Qt-Windows/moc_Counter.o: In function `ZN7Counter18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv':
C:\Documents and Settings\Deloitte\��� ���������\NetBeansProjects\HelloWorld1/moc_Counter.cpp:56: undefined reference to `Counter::slotInc()'
collect2: ���������� ld ����������� � ����� �������� 1
make[2]: *** [dist/Debug/MinGW_Qt-Windows/HelloWorld1.exe] Error 1
make[2]: Leaving directory `/c/Documents and Settings/Deloitte/��� ���������/NetBeansProjects/HelloWorld1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/Documents and Settings/Deloitte/��� ���������/NetBeansProjects/HelloWorld1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
counter.h
#ifndef _Counter_h_
#define _Counter_h_
#include <QObject>
class Counter:public QObject{
Q_OBJECT
private:
int m_nValue;
public:
Counter();
public slots:
void slotInc();
signals:
void goodbye();
void counterChanged(int);
};
的main.cpp
#include <QtGui/QApplication>
#include <QtGui>
#include "Counter.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QLabel lbl("0");
QPushButton cmd ("ADD");
Counter counter;
lbl.show();
cmd.show();
QObject::connect(&cmd, SIGNAL(clicked()),
&counter, SLOT (slotInc()));
QObject::connect(&counter, SIGNAL(counterChanged(int)),
&lbl, SLOT(setNum(int)));
QObject::connect(&counter, SIGNAL (goodbye()), &app, SLOT(quit()));
return app.exec();
}
答案 0 :(得分:0)
您的代码缺少Counter类成员函数的实际定义,特别是Counter::Counter
构造函数和Counter::slotInc
。您必须为它们提供实现。
Counter::goodbye
和Counter::counterChanged
是Qt MOC提供定义的信号。