Kei Minagawa Kei Minagawa -4 years ago 63
C++ Question

In C++ and Qt how can I write these `#include <Q...>` to another few lines?

I wrote some code to create GUI with C++ and Qt. Firstly, I wrote the following

#include <QApplication>
#include <QLabel>
#include <QPushButton>


While writing these lines, I remembered when I used Python and Qt, to use Qt class, I had wrote like this.

from PyQt.Gui import *
from PyQt.GtCore import *


The question is: In C++ how can I write these
#include <Q...>
to another few lines like above?

Here is .cpp file I'm using.

#include <QApplication>
#include <QLabel>
#include <QPushButton>

int main(int argc, char *argv[]){
QApplication app(argc, argv);

/* create label */
QLabel *label = new QLabel("Hello");
label->show();

/* create button */
QPushButton *button = new QPushButton("World");
button->show();

return app.exec();
}


Here is .pro file.

######################################################################
# Automatically generated by qmake (3.1) Sun Mar 19 23:12:24 2017
######################################################################

TEMPLATE = app
TARGET = cppRunOnXcode
INCLUDEPATH += .
CONFIG += debug
QT += widgets


# Input
SOURCES += cppRunOnXcode.cpp

Answer Source

You can include super header, like:

#include <QtWidgets/QtWidgets>
#include <QtCore/QtCore>

Basically, super headers are one-to-one related to Qt Modules.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download