• 4347阅读
  • 4回复

急,错误出在那里?( 看完我这个简单的程序) [复制链接]

上一主题 下一主题
离线amaorn
 

只看楼主 倒序阅读 楼主  发表于: 2006-11-30
//////////////////////////////////
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) ;} 不能用, 为什么??????
离线浪漫天使
只看该作者 1楼 发表于: 2006-11-30
connect( quit, SIGNAL( clicked() ), qApp, SLOT( MyExitSolt( ) ) );

qApp 改成this
离线amaorn

只看该作者 2楼 发表于: 2006-11-30
引用第1楼浪漫天使2006-11-30 09:17发表的“”:
connect( quit, SIGNAL( clicked() ), qApp, SLOT( MyExitSolt( ) ) );
qApp 改成this


太感谢楼上的兄弟了,。刚刚激动了一会
能解释一下为什么改成this的原因马?
还有你知道上面的那个警告是怎么回事马?
离线浪漫天使
只看该作者 3楼 发表于: 2006-11-30
MyExitSolt is the slot of MyMainWindow(this)

you have better look this file
/home/amao/qt-x11-free-3.1.2/include/private/qucomextra_p.h
in line 87
离线amaorn

只看该作者 4楼 发表于: 2006-11-30
我看过了,但是还是没有能力改这个东西?
也不敢乱碰,是不是下载个qt 4用好一点!
快速回复
限100 字节
 
上一个 下一个