[Qt-interest] Optionally deriving from QWidget
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Fri Sep 16 03:51:09 CEST 2011
Hi David,
You always need at least QObject and the Q_OBJECT macro to do signal/slots,
so the non-gui class needs those.
In my case, I have separate projects - one for the gui, and one for console,
each with different flags, and each outputting intermediate files to
different folders. (Otherwise you need to rebuild a single project whenever
you change the compiler flag).
Hope that helps,
Tony.
From: qt-interest-bounces+tony.rietwyk=rightsoft.com.au at qt.nokia.com
[mailto:qt-interest-bounces+tony.rietwyk=rightsoft.com.au at qt.nokia.com] On
Behalf Of David Doria
Sent: Friday, 16 September 2011 7:32 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Optionally deriving from QWidget
I have a class that emits Qt signals. I want to use this class in two ways:
1) Interactive - I want to use this class as part of a Qt GUI application
that can handle the signals.
2) Non-interactive - I want to use this class in a command line application
that does not know about Qt.
I tried defining a compiler flag INTERACTIVE and then doing something like
this:
#ifndef FORM_H
#define FORM_H
#if defined(INTERACTIVE)
#warning "Using interactive!"
#include <QWidget>
class Form : public QWidget
#else
#warning "Not using interactive!"
class Form
#endif
{
#if defined(INTERACTIVE)
Q_OBJECT
public:
public slots:
#endif
};
#endif
but even when the flag is defined, I get some vtable errors.
CMakeFiles/interactive.dir/interactive.cpp.o: In function `Form':
/media/portable/Examples/c++/src/QT/OptionalQt/form.h:14: undefined
reference to `vtable for Form'
/media/portable/Examples/c++/src/QT/OptionalQt/form.h:14: undefined
reference to `vtable for Form'
CMakeFiles/interactive.dir/interactive.cpp.o: In function `~Form':
/media/portable/Examples/c++/src/QT/OptionalQt/form.h:14: undefined
reference to `vtable for Form'
/media/portable/Examples/c++/src/QT/OptionalQt/form.h:14: undefined
reference to `vtable for Form'
Is this the right way to go about this? Can anyone explain where I went
wrong?
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110916/ffe12770/attachment.html
More information about the Qt-interest-old
mailing list