小弟正在学习QT,出现点问题.写了个程序通过点击pushbutton控制lineedit,在控制显示出现问题
代码如下:
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlineedit.h>
#include <qstring.h>
class MyMainWindow : public QWidget
{
public :
MyMainWindow() ;
private :
QPushButton *b1 ;
QPushButton *b2 ;
QPushButton *b3 ;
QPushButton *b4 ;
QLineEdit *ledit ;
QString *text ;
} ;
MyMainWindow :: MyMainWindow()
{
text = new QString("Hello") ;
setGeometry(100,100,400,300) ;
b1 = new QPushButton("Click here to mark the text",this) ;
b1->setGeometry(10,10,300,40) ;
b1->setFont(QFont("Times",18,QFont::Bold,TRUE)) ;
b2 = new QPushButton("Click her to unmark the text",this) ;
b2->setGeometry(10,60,300,40) ;
b2->setFont(QFont("Times",18,QFont::Light,FALSE)) ;
b3 = new QPushButton("Click here to remove the text",this) ;
b3->setGeometry(10,110,300,40) ;
b3->setFont(QFont("Times",18,QFont::Bold)) ;
b4 = new QPushButton("Click here to change the text",this) ;
b4->setGeometry(10,160,300,40) ;
b4->setFont(QFont("Arial",18,QFont :: Light)) ;
ledit = new QLineEdit(*text,this) ;
ledit->setGeometry(10,210,280,30) ;
connect(b1,SIGNAL(clicked()),ledit,SLOT(selectAll())) ;
connect(b2,SIGNAL(clicked()),ledit,SLOT(deselect())) ;
connect(b3,SIGNAL(clicked()),ledit,SLOT(clear())) ;
connect(b4,SIGNAL(clicked()),ledit,SLOT(setText(*text))) ;//问题,不能显示
}
int main(int argc,char **argv)
{
QApplication a(argc,argv) ;
MyMainWindow w ;
a.setMainWidget(&w) ;
w.show() ;
return a.exec() ;
}
[ 此贴被XChinux在2006-10-09 13:11重新编辑 ]