在C++;我该如何写这些`#include<;Q.>;`再接几行? 我编写了一些代码,用C++和Qt创建GUI。首先,我写了以下内容 #include <QApplication> #include <QLabel> #include <QPushButton> 问题是:在C++中,我如何将这些代码>包含< /代码>到另外几行?

在C++;我该如何写这些`#include<;Q.>;`再接几行? 我编写了一些代码,用C++和Qt创建GUI。首先,我写了以下内容 #include <QApplication> #include <QLabel> #include <QPushButton> 问题是:在C++中,我如何将这些代码>包含< /代码>到另外几行?,c++,qt,include,C++,Qt,Include,这是我正在使用的.cpp文件 #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(); /

这是我正在使用的.cpp文件

#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();
}

C++预处理器没有通配符。如果您发现自己重复相同的include并使代码混乱,您可以编写一个伞形标题:

一些标题。h:

#include "a.h"
#include "b.h"
#include "c.h"
#include "d.h"
然后在我的课程中。h:

#include "some_headers

您可以包括超级标题,如:

#include <QtWidgets>
#include <QtCore>
#包括
#包括

基本上,超级报头与QT模块是一一对应的。

一般来说,C++中,你只想包括你所需要的。当您只需要QPushButton和QLabel时,引入所有的QtGUI头是非常浪费的,并且会减慢整个构建过程。@stefaanv:是的,这个问题与此相关。但在这个问题上,OP已经知道了方向。在我的例子中,在理解这个问题之前,我需要理解的是C++基础的ANDROID400的答案。现在我可以理解问题和答案了。当您在pro文件中将模块添加到项目中时(即
QT+=widgets
),目录
qtwidts
会自动添加到您的include目录中。所以,你只需要写
#include
。。。它按我的要求工作。这似乎是我问题的直接答案。@Mike:它也起作用了。多亏了你的建议,我深入到Xcode项目中,找到了makefile,它肯定定义了你提到的路径。我没想到我从这个简单的问题中得到了这么多信息。谢谢。好吧,我不知道。所以现在我明白了,在C++中,没有任何方法可以像Python的代码>导入*<代码>。在Python中,语法上是可能的,但是在C++编程中,没有这样的方法。我学到了很多。非常感谢。
#include "some_headers
#include <QtWidgets>
#include <QtCore>