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
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QObject>
#include <QFile>
#include <QDataStream>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QPushButton>
#include <QWidget>
class MainWindow
: public QWidget { Q_OBJECT
public:
private slots:
void openfile();
void updatefile();
private:
};
#endif // MAINWINDOW_H
and here my constructor
Code:
resize(600,500);
filePath
= new QLineEdit(".\\test.txt",
this);
filePath->setGeometry(10,10,400,20);
open_create->setGeometry(420,10,90,20);
QObject::connect(open_create,
SIGNAL(clicked
()),
this,
SLOT(openfile
()));
updateFile->setGeometry(520,10,70,20);
state
= new QLabel("Ready",
this);
state->setGeometry(10,40,500,50);
state->setWordWrap(true);
state->setAlignment(Qt::AlignTop);
fileContent->setGeometry(10,100,580,390);
}
Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo
check what you get under "Compile Output" during your build
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.
1 Attachment(s)
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
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?
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
Re: error: collect2: ld returned 1 exit status while implementing a simple signal/slo
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.
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