QT Signal / Slot

懵懂的女人 提交于 2019-12-25 01:39:03

问题


I've got a question about signals and slots. In my app, I want to connect a signal from one object to a textEdit in a dialog window. My signal emits a QString; if I violate encapsulation (by making the UI public instead of private) and connect the signal directly to the textEdit it works. But I feel that it's not the right way. If I make something like the following:

connect(m_osgWidget->picker.get(), SIGNAL(setX(QString)), m_addAgentDlg, SLOT(getX(QString)));

where:

void getX(QString)
{
    this->ui.textEdit(QString);
}

It gives me an error that I can't use QString in this this->ui.textEdit(QString); I need the QString from setX() signal pasted into the textEdit of m_addAgentDlg. How this can be done? Where did I make a mistake?


回答1:


I am sorry to say this, but you need to learn basic C++. The proper syntax is this for such things in C++ with Qt:

connect(m_osgWidget->picker.get(), SIGNAL(setX(const QString&)), m_addAgentDlg, SLOT(getX(const QString&)));

// Why do you call it getX? Should it be called setText instead?
void getX(const QString& string)
{
    ui->textEdit->setText(string);
}


来源:https://stackoverflow.com/questions/27336595/qt-signal-slot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!