PDA

View Full Version : This SLOT is not working...



icx
17th August 2010, 21:13
I'm trying to make a really simple application: while I'm writing in this QTextEdit, a QLabel need to be constantly updated and show how many characters the users can still write (similar to Twitter). The Clear button works well, but I can't make a slot to change the text of the QLabel as the user is writing.

I've attached below the sources.

5083
5084
5085

I know that in widget.h I should have used the Q_OBJECT macro, but when I use it I get some "undefined reference to `vtable for MainWidget`" errors. So this following code won't work:




class MainWidget : public QWidget{
Q_OBJECT

QTextEdit *t;
QVBoxLayout *_v;
QString *str;

public:
MainWidget();
~MainWidget();

public slots:
void nothing(QString *s, QTextEdit *text){
*s = text->toPlainText();
}
};

Lykurg
17th August 2010, 21:18
Don't create a QString on the heap, better create it on the stack since it is implicit shared the data will be on the "heap" but you avoid a lot of possible errors. Next, you can't pass values via a connect. you have to get the values in your slot or use a proper signal. And if Q_OBJECT causes errors you have to recompile your project.