Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a define available for Qt gui?

I have just one question: is a define (or something similar) available if you are compiling some code to know if the GUI flag has been set?

I'll explain better. I have some code I want to reuse for different programs in QT. Now, some parts of this code are used just in GUI applications (or better widget applications) and depend on QtGui and QtWidgets. I'd like to put these parts in a conditional block (#if or #ifdef) for them to be compiled only in the projects where the GUI and/or widget libraries are included.

And, before you suggest this, making a library is not a solution. I'd prefer a define...

EDIT:
Probably I didn't explain myself clearly. What I'm looking for is the define associated with the GUI inclusion. Example:

FILE myfile.h

#ifdef THE_QT_GUI_DEFINE_FLAG
#include <QPainter.h>
#endif

PROJECT A: in the QMake file I write:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

PROJECT B: in the QMake file I write:

QT       -= gui

Now, I want QPainter.h to be included just in project A. Do you know what is the define flag set when I add the gui library? I tried with QT_QTGUI_MODULE_H, but it doesn't work (probably because it is used just when you compile THE qt library).

like image 436
frarugi87 Avatar asked Sep 11 '14 13:09

frarugi87


People also ask

How do you create a GUI using C++ with Qt platform?

# Step 1 : Go to file -> new -> Project ->QtGUIApplication->(Change the name of your project) and attention to your Project Location! -> OK ->Next->Next-> Finish. Then you have to click right on Generated File in the Solution Explorer to add ui_Example_1. h file.

Is Qt for C++ or C?

Qt is C++. But you could just write C-style code everywhere that doesn't interact/create GUI elements and compile the whole thing with your C++ compiler of choice.

What is Qt GUI programming?

Qt is used for developing graphical user interfaces (GUIs) and multi-platform applications that run on all major desktop platforms and most mobile or embedded platforms. Most GUI programs created with Qt have a native-looking interface, in which case Qt is classified as a widget toolkit.


1 Answers

Ok, I found it. Inspired by the answers I went to dig in the automatically generated files and, searching through the lib files, i found

Qt\5.2.1\msvc2010\mkspecs\modules\qt_lib_gui.pri

which has the line

QT.gui.DEFINES = QT_GUI_LIB

and then... This is the magic word! :)

Now if i put

#ifdef QT_GUI_LIB
#include <QPainter.h>
#endif

QPainter is included just in the gui-enabled projects.

Thank you all for your help!

like image 51
frarugi87 Avatar answered Sep 30 '22 06:09

frarugi87