• 3923阅读
  • 0回复

[讨论]setText()不起任何作用? [复制链接]

上一主题 下一主题
离线青春岁月
 

只看楼主 倒序阅读 楼主  发表于: 2011-04-27
解决方案
以下是代码:
MainWindow.cpp


#include "mainwindow.h"
#include "mytest.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    label = new QLabel(this);
    QPalette palette;
    palette.setBrush(QPalette::Background,QBrush(QColor(100,149,237)));
    label->setPalette(palette);
    label->setAutoFillBackground(true);

    button = new QPushButton(tr("press"),this);
    label->move(100,0);

    connect(button,SIGNAL(clicked()),this,SLOT(showmy()));
}

MainWindow::~MainWindow()
{

}

void MainWindow::getname(QString str)
{

    label->setText(str);
    qDebug("getname");

}

void MainWindow::showmy(void)
{
    mytest *myt;
    myt = new mytest(this);

    myt->show();
    qDebug("hello");
}


mytest.cpp


#include "mytest.h"
#include "mainwindow.h"


mytest::mytest(QWidget *parent) :
    QWidget(parent)
{
    this->move(20,20);
    this->resize(100,100);

    string = "hello";
    button = new QPushButton(tr("press"),this);
    qDebug("hello");

    connect(button,SIGNAL(clicked()),this,SLOT(setstring()));
}

void mytest::setstring()
{
    MainWindow mymain;
    mymain.getname(string);
    qDebug("setstring");
}
go!   go!  go!  go!
快速回复
限100 字节
 
上一个 下一个