问题
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