//////////////////////////////////
mainwindow.h
//////////////////////////////////
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlcdnumber.h>
#include <qslider.h>
#include <qlineedit.h>
#include <qstring.h>
#include <qlabel.h>
#include <stdlib.h>
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
MyMainWindow();
public slots:
void MyExitSlot();
private:
QPushButton *b1;
QPushButton *b2;
QPushButton *b3;
QLineEdit *ledit;
QPushButton *quit;
QLCDNumber *lcd;
QSlider *slider;
QLabel *label;
};
#endif
//////////////////////////////////////////////////////
mainwindow.cpp
//////////////////////////////////////////////////////
#include "mainwindow.h"
void MyMainWindow::MyExitSlot()
{
exit( 0 );
}
MyMainWindow::MyMainWindow()
{
setGeometry( 0, 0, 800, 800 );
b1 = new QPushButton( "Button 1", this );
b1->setGeometry( 0, 0, 40, 40 );
b1->setFont( QFont( "Times", 18, QFont::Bold ) );
quit = new QPushButton( "quit", this );
quit->setGeometry( 50,50, 40, 40 );
quit->setFont( QFont( "Times", 18, QFont::Bold ) );
connect( quit, SIGNAL( clicked() ), qApp, SLOT( MyExitSolt( ) ) );
lcd = new QLCDNumber( 2, this );
lcd->setGeometry( 100, 100, 100, 100 );
slider = new QSlider( Vertical, this );
slider->setGeometry( 200, 200, 100,100 );
connect( slider, SIGNAL( valueChanged( int ) ), lcd, SLOT( display( int ) ) );
b2 = new QPushButton( "Click here ", this );
b2->setGeometry( 40, 0 ,50, 50 );
b2->setFont( QFont( "Times", 18, QFont::Bold ) );
b3 = new QPushButton( "Click here ", this );
b3->setGeometry( 90, 0 , 50, 50 );
b3->setFont( QFont( "Times", 18, QFont::Bold ) );
ledit = new QLineEdit( "This is a test",this );
ledit->setGeometry( 140, 0, 80, 80 );
connect( b1, SIGNAL( clicked() ), ledit, SLOT( selectALL() ) );
connect( b2, SIGNAL( clicked() ), ledit, SLOT( deselect() ) );
connect( b3, SIGNAL( clicked() ), ledit, SLOT( clear() ) );
}
///////////////////////////////////////
main.cpp
///////////////////////////////////////
#include "mainwindow.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MyMainWindow w;
a.setMainWidget( &w );
w.show();
return a.exec();
}
//////////////////////////////////////////////////////////
make后 无错误是 :有个警告
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:69: 警告:‘struct QUBuffe r’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:77: 警告:‘struct QUType’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:104: 警告:‘struct QUType _Null’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:287: 警告:‘struct QUType _enum’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:307: 警告:‘struct QUType _ptr’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:326: 警告:‘struct QUType _iface’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:345: 警告:‘struct QUType _idisp’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:364: 警告:‘struct QUType _bool’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:383: 警告:‘struct QUType _int’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:403: 警告:‘struct QUType _double’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:423: 警告:‘struct QUType _charstar’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucom_p.h:444: 警告:‘struct QUType _QString’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucomextra_p.h:65: 警告:‘struct QU Type_QVariant’ 有虚函数却没有虚析构函数
/home/amao/qt-x11-free-3.1.2/include/private/qucomextra_p.h:87: 警告:‘struct QU Type_varptr’ 有虚函数却没有虚析构函数
然后我自己定义的欻槽 MyExitSolt(){ exit(0) ;} 不能用, 为什么??????