• 6972阅读
  • 6回复

[讨论]setText()不起任何作用,调用了没反映? [复制链接]

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

只看楼主 倒序阅读 楼主  发表于: 2011-04-27
一个类去调用另一个类的成员函数,在这个成员函数当中的setText()不起作用,怎么解决这个问题?求给力!
go!   go!  go!  go!
离线dbzhang800

只看该作者 1楼 发表于: 2011-04-27
自己检查你的程序,到底有几个对象。你操作的那一个。或者给出你的完整的测试的程序(最长不要超过100行,限制到50行内最好)
离线青春岁月

只看该作者 2楼 发表于: 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!
离线青春岁月

只看该作者 3楼 发表于: 2011-04-27
速求给力?
go!   go!  go!  go!
离线dbzhang800

只看该作者 4楼 发表于: 2011-04-27
答案就是:去看Qt的manual和例子,看看QMainWindow 到底该怎么用,然后再继续。

题外:这个可能对你有帮助(或提示)
http://hi.baidu.com/cyclone/blog/item/d27c41349e32b75b251f14d4.html
离线dbzhang800

只看该作者 5楼 发表于: 2011-04-27
不要一文多发,请考虑删除重复发文!!!!

http://www.beiww.com/doc/oss/smart-questions.html
离线dbzhang800

只看该作者 6楼 发表于: 2011-04-27
除了QMainWindow用法不和常规(你就是当做个widget用的)外,答案就是我1楼第一句话提到的。
快速回复
限100 字节
 
上一个 下一个