views:

599

answers:

2

Hi guys. I have a small trouble with signal/slot in Qt. I have an class wich has public slot:

void doSomething();

In constructor of this class i do:

this->connect( ui->textFrom, SIGNAL(returnPressed()),
               this, SLOT(doSomething()) );

I have QLineEdit - textFrom object.

../moc_mainwindow.cpp:66: undefined reference to `MainWindow::doSomething()'

:-1: error: collect2: ld returned 1 exit status

Help me, please (:

+5  A: 

void doSomething(); looks like a snip from the header file, did you implement the slot itself?

wuub
Yeah... I forget do that :)
Ockonal
+1  A: 

quick note about syntax: Usually you would use either

connect(from, SIGNAL(sig()), to, SLOT(slot()));

which is basically equivalent to

QObject::connect(from, SIGNAL(sig()), to, SLOT(slot()));

Which you'll do if you're calling from somewhere not inside a QObject.
While this syntax:

to->connect(from, SIGNAL(sig()), SLOT(slot()));

is also reasonable. But this syntax:

to->connect(from, SIGNAL(sig()), to, SLOT(slot()));

is just confusing and duplicates code.

shoosh
...and throws a compiler warning, because 5-arg QObject::connect() is a static method...