qt q_object 编译的问题,如何去改?(这个是书上的例子,刚开始学,不懂,求解)
wang@ubuntu:~/Study/Qt/validator$lsMyDouble.cppwang@ubuntu:~/Study/Qt/validator$qmake...
wang@ubuntu:~/Study/Qt/validator$ ls
MyDouble.cpp
wang@ubuntu:~/Study/Qt/validator$ qmake -project
wang@ubuntu:~/Study/Qt/validator$ qmake
wang@ubuntu:~/Study/Qt/validator$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o MyDouble.o MyDouble.cpp
MyDouble.cpp:18: error: no ‘void MyDouble::slotReturnRressed()’ member function declared in class ‘MyDouble’
make: *** [MyDouble.o] Error 1
wang@ubuntu:~/Study/Qt/validator$
MyDouble.cpp:
1 #include<qapplication.h>
2 #include<qwidget.h>
3 #include<qlineedit.h>
4 #include<qvalidator.h>
5 #include<qmessagebox.h>
6 class MyDouble : public QWidget
7 {
8 Q_OBJECT
9 public:
10 MyDouble();
11 private:
12 QDoubleValidator *dvalid;
13 QLineEdit *edit;
14 public slots:
15 void slotReturnPressed();
16 };
17
18 void MyDouble::slotReturnRressed()
19 {
20 QMessageBox *mbox = new QMessageBox("Validation Results", "if you see th is message, the sting you entered in the QLineEdit object is acceptable.", Q MessageBox::Information, QMessageBox::OK, 0, 0);
21 mbox->show();
22 }
23
24 MyDouble::MyDouble()
25 {
26 setGeometry(100, 100, 200, 50);
27
28 dvalid = new QDoubleValidator(0.0, 10.0, 1, this);
29
30 edit = new QLineEdit(this);
31 edit->setGeometry(10, 10, 180, 30);
32 edit->setValidator(dvalid);
33
34 connect(edit, SIGNAL(returnPressed()), this , SLOT(slotReturenPressed()) );
35 }
36 int main(int argc, char **argv)
37 {
38 QApplication a(argc, argv);
39 MyDouble w;
40 w.show();
41 a.exec();
42 return 0;
43 } 展开
MyDouble.cpp
wang@ubuntu:~/Study/Qt/validator$ qmake -project
wang@ubuntu:~/Study/Qt/validator$ qmake
wang@ubuntu:~/Study/Qt/validator$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o MyDouble.o MyDouble.cpp
MyDouble.cpp:18: error: no ‘void MyDouble::slotReturnRressed()’ member function declared in class ‘MyDouble’
make: *** [MyDouble.o] Error 1
wang@ubuntu:~/Study/Qt/validator$
MyDouble.cpp:
1 #include<qapplication.h>
2 #include<qwidget.h>
3 #include<qlineedit.h>
4 #include<qvalidator.h>
5 #include<qmessagebox.h>
6 class MyDouble : public QWidget
7 {
8 Q_OBJECT
9 public:
10 MyDouble();
11 private:
12 QDoubleValidator *dvalid;
13 QLineEdit *edit;
14 public slots:
15 void slotReturnPressed();
16 };
17
18 void MyDouble::slotReturnRressed()
19 {
20 QMessageBox *mbox = new QMessageBox("Validation Results", "if you see th is message, the sting you entered in the QLineEdit object is acceptable.", Q MessageBox::Information, QMessageBox::OK, 0, 0);
21 mbox->show();
22 }
23
24 MyDouble::MyDouble()
25 {
26 setGeometry(100, 100, 200, 50);
27
28 dvalid = new QDoubleValidator(0.0, 10.0, 1, this);
29
30 edit = new QLineEdit(this);
31 edit->setGeometry(10, 10, 180, 30);
32 edit->setValidator(dvalid);
33
34 connect(edit, SIGNAL(returnPressed()), this , SLOT(slotReturenPressed()) );
35 }
36 int main(int argc, char **argv)
37 {
38 QApplication a(argc, argv);
39 MyDouble w;
40 w.show();
41 a.exec();
42 return 0;
43 } 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询