首页| 论坛| 消息

标题:qt求助
作者:kidiger
日期:2006-09-27 10:21
内容:

小弟正在学习QT,出现点问题.写了个程序通过点击pushbutton控制lineedit,在控制显示出现问题
代码如下:
#include
#include
#include
#include
#include
#include
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,ar ..


#1 [wangowen 09-27 14:11]
程序问题,主要在信号和槽的连接上, 在Qt4里deselect不是QlineEdit的槽,我想你的第二个功能不选择应该实现不了。
第四个连接,clidked()没有带参数,所以槽setText(*text)会把参数忽略掉,所以你应该自己定义一个槽
#2 [wangowen 09-27 14:41]
把每个窗口看成一个窗口部件,定义实现分开放在两文件里(这是好习惯)。
我用的是Qt4
#3 [kidiger 09-27 16:20]
谢谢
我的是RH9,是QT3.1
#4 [axlrose 09-28 09:59]
class MyMainWindow : public QWidget
{
Q_OBJECT
public :
MyMainWindow() ;
private :

回复 发表
主题 版块