• 4150阅读
  • 1回复

我的程序出啥问题了? [复制链接]

上一主题 下一主题
离线xiaodong3727
 

只看楼主 正序阅读 楼主  发表于: 2010-05-30
#include<QApplication>
#include<QLabel>
#include<QPushButton>
#include<QHBoxLayout>
#include<QSlider>


void setLabel(QLabel *label);

int main(int argc,char *argv[])
{

QApplication app(argc,argv);
QWidget *window=new QWidget;
window->setWindowTitle("WINDOWS窗口");//创建主窗体
QHBoxLayout *layout=new QHBoxLayout;
QLabel *label=new QLabel("<h2><i><font color=red>Hello</font></i></h2>");//子窗体
QPushButton *btn=new QPushButton("click me!");//子窗体
//QObject::connect(btn,SIGNAL(clicked()),&app,SLOT(quit()));
QObject::connect(btn,SIGNAL(clicked()),label,SLOT(setLabel(QLabel *)));
layout->addWidget(label);
layout->addWidget(btn);
window->setLayout(layout);
window->show();
return app.exec();
}
//我想实现点击按钮后,标签的字体变成 changed.可惜不行。。。我知道是局部变量的问题。请问有什么办法实现?
void setLabel(QLabel *label)
{
label->setText("changed");
label->setVisible(false);
}
离线hgamesale
只看该作者 1楼 发表于: 2010-05-31
QObject::connect(btn,SIGNAL(clicked()),label,SLOT(setText("change"));

快速回复
限100 字节
 
上一个 下一个