htroyo
2nd May 2011, 03:18
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
#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:
MainWindow(QWidget *parent = 0);
private slots:
void openfile();
void updatefile();
private:
QLabel *state;
QLineEdit *filePath;
QTextEdit *fileContent;
QPushButton *open_create;
QPushButton *updateFile;
QFile *file;
QDataStream *ds;
};
#endif // MAINWINDOW_H
and here my constructor
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
resize(600,500);
filePath = new QLineEdit(".\\test.txt",this);
filePath->setGeometry(10,10,400,20);
open_create = new QPushButton("Open/Create",this);
open_create->setGeometry(420,10,90,20);
QObject::connect(open_create,SIGNAL(clicked()),thi s,SLOT(openfile()));
updateFile = new QPushButton("Update file",this);
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 = new QTextEdit(this);;
fileContent->setGeometry(10,100,580,390);
}
#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:
MainWindow(QWidget *parent = 0);
private slots:
void openfile();
void updatefile();
private:
QLabel *state;
QLineEdit *filePath;
QTextEdit *fileContent;
QPushButton *open_create;
QPushButton *updateFile;
QFile *file;
QDataStream *ds;
};
#endif // MAINWINDOW_H
and here my constructor
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
resize(600,500);
filePath = new QLineEdit(".\\test.txt",this);
filePath->setGeometry(10,10,400,20);
open_create = new QPushButton("Open/Create",this);
open_create->setGeometry(420,10,90,20);
QObject::connect(open_create,SIGNAL(clicked()),thi s,SLOT(openfile()));
updateFile = new QPushButton("Update file",this);
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 = new QTextEdit(this);;
fileContent->setGeometry(10,100,580,390);
}