Results 1 to 2 of 2

Thread: signals and slots, test example doesn't compile

  1. #1
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, test example doesn't compile

    hello, i'm new using Qt, i tried to run an example using custom slots, here is the code:
    Qt Code:
    1. #include <QObject>
    2. #include <QApplication>
    3. #include <QWidget>
    4. #include <QPushButton>
    5. #include <QLabel>
    6.  
    7. class Class1 : public QWidget {
    8. Q_OBJECT
    9. public:
    10. Class1(QWidget *p = 0) : QWidget(p) {
    11. b = new QPushButton("Click",this);
    12. l = new QLabel("Label",this);
    13. b->resize(100,30);
    14. b->move(10,60);
    15. l->resize(100,30);
    16. l->move(10,10);
    17. QObject::connect(b,SIGNAL(clicked()),this,SLOT(setl()));
    18. }
    19. public slots:
    20. void setl() {
    21. l->setText("TEXT123");
    22. }
    23.  
    24. private:
    25. QLabel *l;
    26. };
    27.  
    28. int main(int argc, char *argv[])
    29. {
    30. QApplication app(argc, argv);
    31.  
    32. Class1 *c = new Class1();
    33. c->move(300,100);
    34. c->resize(120,100);
    35. c->show();
    36.  
    37. return app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 
    and if i try to build the app i get this error:
    Qt Code:
    1. :: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    what is wrong?


    Added after 19 minutes:


    well, i found the solution, it's because i was doing that in a bad way, i use a Class1.h, Class1.cpp and main.cpp as i should do...
    Sometimes i'm too lazy and i just write down all my code in a single file because i dont want to use .h's hahahahha, well i know how to do it later, thanks anyway
    Last edited by htroyo; 16th April 2011 at 04:10.

  2. #2
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, test example doesn't compile

    add such a line:
    Qt Code:
    1. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. about signals and slots
    By Sandip in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2008, 16:02
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 08:11
  4. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12

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.