0

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?

TriskalJM
  • 2,393
  • 1
  • 19
  • 20
Azraith Sherkhan
  • 131
  • 2
  • 11

1 Answers1

2

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);
}
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Well, i still learn so it's not necessary to say. I have tried every possible type of code posted above, including one that you provided. It doesn't work. Thats why i ask it here. I continue get messages that there is no such slot in object. – Azraith Sherkhan Dec 07 '14 at 00:46
  • 2
    @AzraithSherkhan: you have to rerun qmake, but please buy a C++ book. It is necessary to say as these situations are why the authors spent their lives with them. – László Papp Dec 07 '14 at 01:15