PDA

View Full Version : Problems with Q_OBJECT macro



dbrmik
20th February 2009, 14:14
Hi

I am having a bizarre problem with Q_OBJECT macro, if I include the maco in my class declaration the program does not run with the error

"You can't do that without a process to debug"



#include <qwt_plot.h>

class QSpinBox;
class QVBoxLayout;
class QDialog;
class Fitting;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FittingPlot : public QwtPlot
{
Q_OBJECT //the program runs if this is if commented out

public:
FittingPlot(QWidget *parent = NULL);

public slots:
void upd();

private:
QSpinBox* aSpinBox;
QSpinBox* bSpinBox;
QVBoxLayout* layout;
QDialog* diag;

Fitting* tfit;
int mtest;
};


This the implementation



#include <qwt_plot.h>
#include <QtGui>

#include "FittingPlot.h"
#include "Fitting.h"

FittingPlot::FittingPlot(QWidget *parent)
:QwtPlot(parent),mtest(0)

{
aSpinBox = new QSpinBox;
bSpinBox = new QSpinBox;
layout = new QVBoxLayout();
layout->addWidget(aSpinBox);
layout->addWidget(bSpinBox);
diag=new QDialog(this);
diag->setLayout(layout);
diag->show();

tfit=new Fitting();

QObject::connect(aSpinBox,SIGNAL(valueChanged(int) ),tfit, SLOT(setTargetThreshold(int)) );
QObject::connect(aSpinBox,SIGNAL(valueChanged(int) ),tfit, SLOT(run()) );
QObject::connect(aSpinBox,SIGNAL(valueChanged(int) ),this, SLOT(upd()) );
}

void
FittingPlot::upd()
{
mtest++;
}



When the code does run (with Q_OBJECT commnented out, the slot upd does not get called with warnin message

"warning: Object::connect: No such slot QwtPlot::upd()

The other two slots work in the Fitting Class work OK

Does anyone have any ideas why this is happening?

spirit
20th February 2009, 15:17
try to remove #include <qwt_plot.h> from cpp, but I think this not a problem.

dbrmik
20th February 2009, 15:34
Thanks for the advice, but I still does not work, I still get the error

"You can't do that without a process to debug"

I am using eclipse on winXp.

I also get the same problem with QDevelop but different error

Program received signal SIGSEGV, Segmentation fault.
Program exited with code 030000000005.

Anyone any ideas?

Thanks

talk2amulya
20th February 2009, 15:47
could the crash be because u have three different slots connected to the same signal and the order in which they r executed might not be appropriate and is causing the crash?

dbrmik
20th February 2009, 16:17
Thanks but no that isn't the problem, the slot functions are presently dummy functions and the call order doesn't matter.

I have rejigged the code, rather than inherit from QwtPlot, I inherit from QWidget, it runs Ok (i.e displays the Widget). The problem is that I want to inherit from QwtPlot

Thanks

spirit
20th February 2009, 16:20
maybe you should better as this question in Qwt subforum and Uwe probably helps you :)

dbrmik
20th February 2009, 16:46
Thanks Spirit, I will:)

wysota
22nd February 2009, 14:31
Did you remember to rerun qmake after adding the macro? For me it looks like the program fails to rebuild with the macro thus the message you get. Qwt has nothing to do with it.

Amrita Singh
23rd February 2009, 05:57
i agree with wysota. please make a clean metaobject file which qmake already does,
start with a new pro file, a new environment .
moc -o x_moc x.h

add the moc file in the main cpp file
#include "x_moc"

kindly read Q_OBJECT problems due to moc..

it may not exactly solve the problem but good to give a try.

adamatic
23rd February 2009, 07:32
Are you sure it is correct the eclipse configuration? becuase maybe there is a Eclipse problem to find the debugger. Specify the gdb ruth in debug configuration.

And have you include the QT and the compiler (MinGw) in the CLASS PATH?

Cheers

dbrmik
23rd February 2009, 08:57
Hi

I dont think it is an eclipe/qt problem as I have other qt/qwt projects that work just fine

If my class inherits from QWidget, I dont have a problem, only when inheriting from QwtPlot

Thanks

wysota
23rd February 2009, 10:10
Please provide a minimal compilable example reproducing the problem.

dbrmik
23rd February 2009, 11:34
I have attached the project as a zip file, hope that OK

spirit
23rd February 2009, 12:37
try this


class FittingPlot: public QwtPlot
{
Q_OBJECT
public:
FittingPlot(QWidget *parent = 0) ;
....
};

FittingPlot::FittingPlot(QWidget *parent)
: QwtPlot(parent)
{
}

dbrmik
23rd February 2009, 13:09
Thanks but I still get the same error

"You can't do that without a process to debug."

Grrr

spirit
23rd February 2009, 13:12
did you rebuild all project? did you remove old obj-files? did you run qmake after cleaning project dir?

dbrmik
23rd February 2009, 13:29
Yes, after cleaning the project I checked the files were deleted Ok. I think Eclipse handles the Qmake process, however I did it manually from the command line. But I still get the same error.


Thanks

wysota
23rd February 2009, 19:26
I have attached the project as a zip file, hope that OK

It works for me without a problem. A simple qmake && make compiled the project just fine. I have Qwt 5.1.1 installed with Qt 4.4.3.

dbrmik
24th February 2009, 08:40
Thanks wysota, that's good to know. Still not working here, I also have Qwt 5.1.1 installed with Qt 4.4.3 running on xp using eclipse. I get the same problem usng QDevelop. As I metioned earlier I have other projects using the qwt library, however I am not subclassing QwtPlot, I'm adding it as a widget to a MainWindow with no problems, I suppose I'll have to live with it for now

Thanks once again for your time

sylvainb
24th February 2009, 21:32
What happens if in FittinPlot.cpp you substitute '#include "FittingPlot.h' for '#include "FittinPlot.moc"'?

wysota
24th February 2009, 23:54
Don't use any IDEs if you want to pinpoint a problem. Use plain qmake && make combination, it's the most reliable you can get.

Bjoern
26th February 2009, 14:10
First of all:
The output you're reporting is simply the message of Eclipse complaining that it can't run the debugger after your program crashed, so your Eclipse isn't set up properly.

So set up your gdb in Eclipse, start the program in debug mode and see where it crashes. Figure out what's wrong (possible not initialized ptr / member) and fix it.

Aren't you used to work with debuggers :confused:

Another thing:
It makes perfectly sense that the upd slot isn't available on connection w/o moc generating the meta info for your QObject.
The other slots you're connecting are already defined in QWidget (which gets inherited by QwtPlot), which has the macro, so they are known.

Make sure you dig again trough the Qt documentation and get the difference between an C++ object (which you get by subclassing) and Qt META objects (which require an additional Q_OBJECT macro to be created).
See QObject::staticMetaObject() ...

Hope this helps somehow to get things together and didn't confuse too much :rolleyes:

regards,
Bjoern