PDA

View Full Version : Problems with the Q_OBJECT-Macro



tokstolle
23rd March 2009, 15:52
Hello out there,
I have so troubble building a small app. My main.cpp has this easy structur:
#include "qtexplorer.h"

#include <QtGui>
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtExplorer w = new QtExplorer;
w.show();
return a.exec();
}

my QtExplorer.h looks like this:
#ifndef QTEXPLORER_H
#define QTEXPLORER_H

#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include "ui_qtexplorer.h"

class QtExplorer : public QWidget
{
Q_OBJECT

public:
QtExplorer(QWidget *parent = 0);
~QtExplorer();

private:
Ui::QtExplorerClass ui;
long req_id;
private slots:
int ReadRegister();
int WriteRegister();
int ReadMem();
int WriteMem();
};

#endif // QTEXPLORER_H


So, what is my problem? I cannot build this easy code because there is an error at the first curly brace in the qtexplorer.h (this comes of the eclipse integration plugin) which says: "within this context".
After that brace comes the macro Q_OBJECT. Without this macro I cannot define slots. But what can I do to clear this error?

Thank you in advance..

Sincerely Tok

spirit
23rd March 2009, 15:54
what the strange code


...
QtExplorer w = new QtExplorer;
w.show();
...

;)
modify it


...
QtExplorer w;
w.show();
...

tokstolle
23rd March 2009, 16:04
Thanks now it works. But what is the difference? Why I cannot call it by the usual methode?

Sincerely Tok

Lykurg
23rd March 2009, 16:09
QtExplorer *w = new QtExplorer();
w->show();
delete w;

or


QtExplorer w;
w.show();

Once you create the object on the heap, once on the stack.

QtExplorer w = new QtExplorer(); is just invalid code...

tokstolle
23rd March 2009, 16:31
Okay thank you.
The reason why I changed it to a new()-constructor is, that I cannot debug the small program. If I start the debugger (under Eclipse Qt-integration, Linux) I get the message "No symbol "new" in current context." on the eclipse-console. I thought this isn't serious but I tied with a new()-operator.
I start debugging with the main-method (obvious) but if I jump to the construction point ( QtExplorer w; ) the sourcecode-window is closed with a message "No source available for "" " and if I go one step further, the whole execution stops with the message "Cannot find bounds of current function".

What is the meaning of that? (I installed the libqt-dbg!)

Thank you in advance

Sincerely Tok

tokstolle
23rd March 2009, 16:52
Ahhh, Im one step further.
But now gdb on eclipse stucks with the message:

Can't find a source file at "widgets/qlineedit.h"
Locate the file or edit the source lookup path to include its location.

So where should this source-code installed? I thought I have it all with the qt4-dev-package of debian?

Thank you

Sincerely Tok

Lykurg
23rd March 2009, 18:09
a) did you use #include <QLineEdit>?
b) Look, if under project->properties->C++ Include paths the right directories are set.