Results 1 to 9 of 9

Thread: error: collect2: ld returned 1 exit status while implementing a simple signal/slot

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

    Default error: collect2: ld returned 1 exit status while implementing a simple signal/slot

    hello, i posted some days ago a problem with that error, but i noticed that i have to use it whit a .h and a separated .cpp, but know i cant find the solution, i just want to create a program to read, edit and update a file, but if i use the Q_OBJECT macro i get that error, i tried include the QObject header,including all widget classes in .h and tried in .cpp and i always get that error, here is my code
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QObject>
    5. #include <QFile>
    6. #include <QDataStream>
    7. #include <QLabel>
    8. #include <QLineEdit>
    9. #include <QTextEdit>
    10. #include <QPushButton>
    11. #include <QWidget>
    12.  
    13. class MainWindow : public QWidget {
    14. Q_OBJECT
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17. private slots:
    18. void openfile();
    19. void updatefile();
    20. private:
    21. QLabel *state;
    22. QLineEdit *filePath;
    23. QTextEdit *fileContent;
    24. QPushButton *open_create;
    25. QPushButton *updateFile;
    26. QFile *file;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    and here my constructor
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
    2.  
    3.  
    4. resize(600,500);
    5.  
    6. filePath = new QLineEdit(".\\test.txt",this);
    7. filePath->setGeometry(10,10,400,20);
    8.  
    9. open_create = new QPushButton("Open/Create",this);
    10. open_create->setGeometry(420,10,90,20);
    11. QObject::connect(open_create,SIGNAL(clicked()),this,SLOT(openfile()));
    12.  
    13. updateFile = new QPushButton("Update file",this);
    14. updateFile->setGeometry(520,10,70,20);
    15.  
    16. state = new QLabel("Ready",this);
    17. state->setGeometry(10,40,500,50);
    18. state->setWordWrap(true);
    19. state->setAlignment(Qt::AlignTop);
    20.  
    21. fileContent = new QTextEdit(this);;
    22. fileContent->setGeometry(10,100,580,390);
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    check what you get under "Compile Output" during your build

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    Ensure you run qmake.

    If you want the .h and .cpp in the same file, add #include "filename.moc" to your cpp.

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

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    here it is the compiler output, i dont understand the error message...
    and if i remove the Q_OBJECT macro it builds correctly, but signals doesnt work
    Attached Images Attached Images

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    Yes, that error message means a missing moc, see my post above.

    Q_OBJECT is required for signals to function.

    Did you run qmake?

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

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    hello, thanks for replying, i dont know so much about qmake command, but i right clicked on project name and picked run qmake, and it just told me that process exited normally, i rebuilded the project and i got the same error

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

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    any suggestion please?

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    You could post your complete output log so we can see if the moc files are being compiled and linked.

    Or you could post your code in an archived format and we can see if we can replicate the problem.

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

    Default Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo

    well, thanks everyone for replying... i don't know what happened, but i just copied the .h and .cpp files, then i added them to a new project and it builds correctly and signals work ok, i don't know why and how but i works hahahaah
    thanks anyway

Similar Threads

  1. error: collect2: ld returned 1 exit status
    By Splatify in forum Newbie
    Replies: 2
    Last Post: 13th February 2011, 18:09
  2. Replies: 7
    Last Post: 10th February 2011, 23:35
  3. error: collect2: ld returned 1 exit status
    By srohit24 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2009, 06:32
  4. error: collect2: ld returned 1 exit status
    By nataly in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2009, 13:39
  5. collect2: ld returned 1 exit status error
    By gmsk19 in forum Qt Tools
    Replies: 11
    Last Post: 25th July 2009, 02:05

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.