main.cpp:
#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QWidget>
class CMywin : public QWidget
{
Q_OBJECT
public:
CMywin(QWidget *parent=0);
QLabel *label1;
QPushButton *button1;
QPushButton *button2;
private slot:
void button1click();
void button2click();
};
CMywin::CMywin(QWidget *parent)
:QWidget(parent)
{
label1=new QLabel(tr("label1"));
button1 = new QPushButton(tr("button1"));
connect(button1, SIGNAL(clicked()), this, SLOT(button1click()));
button2 = new QPushButton(tr("button2"));
connect(button2, SIGNAL(clicked()), this, SLOT(button2click()));
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addStretch();
buttonsLayout->addWidget(label1);
buttonsLayout->addWidget(button1);
buttonsLayout->addWidget(button2);
setLayout(buttonsLayout);
}
void CMywin::button1click()
{
label1->setText("hello");
}
void CMywin::button2click()
{
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CMywin mywin;
mywin.show();
return app.exec();
}
命令如下:
qmake -project 正常
qmake 正常
make
错误信息:
E:\test>make
make -f Makefile.Debug
make[1]: Entering directory `E:/test'
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
-DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"D:/Qt/QT4.1.
0/include/QtCore" -I"D:/Qt/QT4.1.0/include/QtGui" -I"D:/Qt/QT4.1.0/include" -I".
" -I"D:/Qt/QT4.1.0/include/ActiveQt" -I"debug" -I"." -I"D:/Qt/QT4.1.0/mkspecs/wi
n32-g++" -o debug\main.o main.cpp
main.cpp:43: error: expected `:' before "slot"
main.cpp:44: error: expected primary-expression before "void"
main.cpp:44: error: ISO C++ forbids declaration of `slot' with no type
main.cpp:44: error: expected `;' before "void"
main.cpp:63: error: no `void CMywin::button1click()' member function declared in
class `CMywin'
main.cpp:77: error: no `void CMywin::button2click()' member function declared in
class `CMywin'
main.cpp:77: error: `void CMywin::button2click()' and `void CMywin::button2click
()' cannot be overloaded
make[1]: *** [debug\main.o] Error 1
make[1]: Leaving directory `E:/test'
make: *** [debug] Error 2
我是新手,这是怎么回事啊。先谢过了。
[ 此贴被fanyu在2006-02-16 12:09重新编辑 ]