[Qt-interest] Optionally deriving from QWidget

Malyushytsky, Alex alex at wai.com
Fri Sep 16 00:15:20 CEST 2011


As for me  the right way  is to have 2 classes.

One class - not derived from QWidget where you have all functionality which is not Qt dependend,
Another can be derived from both QWidget and 1st class.

There is no advantages in using preprocessor definition.

As for why you get errors - it is difficult to say, especially since it is not clear what you do in the CMake.
I would only advice to check if moc file was generated, cause symptoms make me think it was not
As far as I recall you have to do it explicitly with CMake.

Regards,
     Alex


From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of David Doria
Sent: Thursday, September 15, 2011 2:32 PM
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


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110915/112fc7ac/attachment.html 


More information about the Qt-interest-old mailing list