Results 1 to 2 of 2

Thread: This SLOT is not working...

  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default This SLOT is not working...

    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.

    main.cpp
    widget.cpp
    widget.h

    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:

    Qt Code:
    1. class MainWidget : public QWidget{
    2. Q_OBJECT
    3.  
    4. QString *str;
    5.  
    6. public:
    7. MainWidget();
    8. ~MainWidget();
    9.  
    10. public slots:
    11. void nothing(QString *s, QTextEdit *text){
    12. *s = text->toPlainText();
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: This SLOT is not working...

    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.

Similar Threads

  1. Signal and Slot connection not working !!
    By prakash437 in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2010, 10:16
  2. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55
  3. QObject signal/slot not working
    By Msnforum in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 22:50
  4. Signal Slot not working
    By munna in forum Qt Programming
    Replies: 8
    Last Post: 6th November 2006, 10:36
  5. Slot not working
    By dayrinni in forum Newbie
    Replies: 5
    Last Post: 4th September 2006, 06:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.