我先从QWidget派生了my2base,然后再从my2base派生my2
在my2中建立了一个PushButton到copy()的连接,但在编译时出错:
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/friendly-arm/x86-qtopia/qt/include -I/friendly-arm/x86-qtopia/qtopia/include -o my2.o my2.cpp
my2.cpp: In constructor `my2::my2(QWidget*, const char*, unsigned int)':
my2.cpp:8: no matching function for call to `my2::connect(QPushButton*&, const
char[11], QObject*, const char[8])'
/friendly-arm/x86-qtopia/qt/include/qobject.h:110: candidates are: static bool
QObject::connect(const QObject*, const char*, const QObject*, const char*)
/friendly-arm/x86-qtopia/qt/include/qobject.h:210: bool
QObject::connect(const QObject*, const char*, const char*) const
make: *** [my2.o] Error 1
源代码如下,my2base.h 和my2base.cpp都是designer自动生成的
-------------------------------------------------------------------------------------------------------------
my2base.h
/****************************************************************************
** Form interface generated from reading ui file 'my2base.ui'
**
** Created: Fri Jan 20 20:57:41 2006
** by: The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef MY2BASE_H
#define MY2BASE_H
#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QLineEdit;
class QPushButton;
class my2base : public QWidget
{
Q_OBJECT
public:
my2base( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~my2base();
QLineEdit* LineEdit1;
QLineEdit* LineEdit2;
QPushButton* PushButton1;
};
#endif // MY2BASE_H
--------------------------------------------------------------------------------------------------------
下面是my2base.cpp
/**************************************************************************
** Form implementation generated from reading ui file 'my2base.ui'
**
** Created: Fri Jan 20 20:57:41 2006
** by: The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "my2base.h"
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
/*
* Constructs a my2base which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
my2base::my2base( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
if ( !name )
setName( "my2base" );
resize( 255, 153 );
setCaption( tr( "my2" ) );
LineEdit1 = new QLineEdit( this, "LineEdit1" );
LineEdit1->setGeometry( QRect( 30, 60, 131, 25 ) );
LineEdit2 = new QLineEdit( this, "LineEdit2" );
LineEdit2->setGeometry( QRect( 30, 100, 131, 25 ) );
PushButton1 = new QPushButton( this, "PushButton1" );
PushButton1->setGeometry( QRect( 180, 60, 61, 51 ) );
PushButton1->setText( tr( "PushButton1" ) );
}
/*
* Destroys the object and frees any allocated resources
*/
my2base::~my2base()
{
// no need to delete child widgets, Qt does it all for us
}
--------------------------------------------------------------------------------------------------------
下面是my2.h
#include "my2base.h"
class my2 : public my2base
{
Q_OBJECT
public:
my2(){}
my2(QWidget*, const char* , WFlags);
~my2();
protected slots:
void copy();
};
--------------------------------------------------------------------------------------------------------
下央是my2.cpp
#include "my2.h"
#include<qlineedit.h>
my2::my2( QWidget* parent, const char* name, WFlags fl ):
my2base( parent, name, fl )
{
//signals and slots connections
connect( PushButton1 , SIGNAL( clicked() ), (QObject*)this, SLOT( copy() ) );
}
my2::~my2()
{}
void my2::copy()
{
//PushButton1->validateAndSet( x, 0, 0, 0);
QString x = LineEdit1->text();
LineEdit2->setText(x);
}
[ 此贴被XChinux在2006-01-20 23:51重新编辑 ]