QT QLable setText(QString)不显示QString里的内容 5
#include"dlgyao.h"#include<cstdio>#include<cstdlib>#include<ctime>DlgYao::DlgYao(QWid...
#include "dlgyao.h"
#include <cstdio>
#include <cstdlib>
#include <ctime>
DlgYao :: DlgYao(QWidget *parent)
: QWidget(parent)
{
this->resize(WIN_WIDTH,WIN_HEIGHT);
this->move(1920 / 2 - 200,1080 / 2 - 150);
lbl = new QLabel(this);
lbl->setIndent(50);
lbl->setMargin(200 / 2);
//lbl->setText();
btn = new QPushButton(QString("start"),this);
btn->resize(BTN_WIDTH,BTN_HEIGHT);
btn->move(WIN_WIDTH / 2 - BTN_WIDTH/2,WIN_HEIGHT /2 + BTN_HEIGHT /2);
srand(time(0));
//绑定线程和我们的信号函数
connect(btn,SIGNAL(clicked()),this,SLOT(ChText()));
}
void DlgYao :: ChText()
{
//实现改变细节
int num;
num = rand() % 10;
str = lbl->text() + QString::number(num);
//str明明有值,为什么输出不出来??
lbl->setText(str);
lbl->repaint();
printf("%s\n",str.toAscii().data());
}
DlgYao :: ~DlgYao()
{
delete lbl;
delete btn;
}
我在标准输出中明明看到str有值,为什么setText却无法输出?掉了repaint重画也没用。 展开
#include <cstdio>
#include <cstdlib>
#include <ctime>
DlgYao :: DlgYao(QWidget *parent)
: QWidget(parent)
{
this->resize(WIN_WIDTH,WIN_HEIGHT);
this->move(1920 / 2 - 200,1080 / 2 - 150);
lbl = new QLabel(this);
lbl->setIndent(50);
lbl->setMargin(200 / 2);
//lbl->setText();
btn = new QPushButton(QString("start"),this);
btn->resize(BTN_WIDTH,BTN_HEIGHT);
btn->move(WIN_WIDTH / 2 - BTN_WIDTH/2,WIN_HEIGHT /2 + BTN_HEIGHT /2);
srand(time(0));
//绑定线程和我们的信号函数
connect(btn,SIGNAL(clicked()),this,SLOT(ChText()));
}
void DlgYao :: ChText()
{
//实现改变细节
int num;
num = rand() % 10;
str = lbl->text() + QString::number(num);
//str明明有值,为什么输出不出来??
lbl->setText(str);
lbl->repaint();
printf("%s\n",str.toAscii().data());
}
DlgYao :: ~DlgYao()
{
delete lbl;
delete btn;
}
我在标准输出中明明看到str有值,为什么setText却无法输出?掉了repaint重画也没用。 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询