(C++)Code:: 块无法识别 QT4 类
到目前为止,我一直在控制台中工作,几天前决定尝试 QT GUI。 我下载了QT SDK,安装它,调整QT的位置并 设置PATH环境变量->按照网站上的说明。
我在Code::Blocks-in中打开了一个新的Qt4项目,看起来一切正常。 默认情况下有一个示例:
#include <QApplication>
#include <QFont>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
Started it and it was all OK。
之后我去了官方网站上的教程,那里有一个最终的例子。 某种简单的游戏。我已经复制粘贴了所有 .h 和 .cpp 文件,然后将 他们在当前的项目中看看它是如何工作的,但随后出现了问题。
Code::Blocks 无法识别某些类。 例如 :: #include QTimer :没有这样的文件或目录 #include QRect :没有这样的文件或目录
我卸载了 QT 并重新安装并再次配置了所有内容,但问题并未消失。
这些类不起作用,也不在默认示例中 ::
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QTimer> does not have real purpose , just for illustration
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
ba\107\main.cpp|4|QTimer:没有这样的文件或目录| ||=== 构建完成:1 个错误,0 个警告 ===|
我现在不知道有多少类不能正常工作,这只是其中的一些。
不要在谷歌上寻找解决方案,也许对你们中的一些人来说几天都没有热水 ,这是一个非常简单的问题。
谢谢
So far I have worked in the console and a few days ago decided to try the QT GUI.
I downloaded the QT SDK , install it, adjust the location of QT and
set up the PATH Environment Variable -> per the instructions on the site.
I opened a new Qt4 project in Code:: Blocks-in and it seemed that everything was OK.
There is by default an example:
#include <QApplication>
#include <QFont>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
Started it an it was all OK.
After that I went to a tutorial on the official site and there is a final example.
Some kind of simple game.I have done copy-paste of all .h and .cpp files and then put
them in current project to see how it works but then problems arise.
Code::Blocks does not recognize some classes.
For example :: #include QTimer : No such file or directory
#include QRect : No such file or directory
I uninstall QT and re-installed and configured everything again but the problem does not go out.
These classes are not working nor in the default example ::
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QTimer> does not have real purpose , just for illustration
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
ba\107\main.cpp|4|QTimer: No such file or directory|
||=== Build finished: 1 errors, 0 warnings ===|
I dont now how much classes don work properly , this is just some of them.
Not to reveal hot water for days on google looking for a solution, maybe for some of you
, this is a bizarrely easy problem.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要花时间研究默认的包含搜索路径,或者只提供您想要包含的标头的更明确的路径。我能够在 Windows XP/32 和之前安装的 Qt 4.6 上使用 Code::Blocks 10.05(带有捆绑的 gcc)重现您的问题。这是我能够毫无问题地构建的代码的略有更改的版本:
查看您的 Qt 安装目录。如果您在使用任何其他标头时遇到此问题,您将能够看到包含目录以及所有标头在其中的位置。看起来 Code::Blocks 项目默认将 QtGui 目录设置为包含搜索路径,这就是为什么您不需要明确提及它来包含 QPushButton 等。
You need to either spend time monkeying with the default include search path, or else just provide a more explicit path the header you want to include. I was able to reproduce your problem with Code::Blocks 10.05 (with bundled gcc) on Windows XP/32 and a previously installed Qt 4.6. Here is the slightly changed version of your code that I was able to build without any problem:
Take a look in your Qt install directory. You'll be able to see the include directory, and where all the headers are within it if you run into this problem with any other headers. It looks like the Code::Blocks projects sets up the QtGui directory as an include search path by default, which is why you didn't need to explicitly mention it for including QPushButton and whatnot.
Code::Blocks 只是一个 IDE,而不是编译器/链接器工具链,因此 Code::blocks 无法找到这些文件,您只是没有配置您的项目来使用它们。
“没有这样的文件或目录”是预处理器错误消息;您仍然需要告诉编译器在哪里可以找到您的第三方头文件。此外,在链接时,您需要告诉链接器在哪里可以找到库。
Code::Blocks is only an IDE not a Compiler/Linker toolchain, so it is not Code::blocks that cant find the files, you have simply not configured your project to use them.
"No such file or directory" is a pre-processor error message; you still have to tell the compiler where to find your third-party header files. Moreover when it comes to linking, you will need to tell the linker where to find the libraries.
每当您有
#include
(带有尖括号<>
)时,编译器都会在默认包含路径中查找。您需要将 Qt include 目录放入项目的 include 路径中。我不确定这是如何在 Code::Blocks 中完成的。它可能位于项目设置中的某个位置。Whenever you have an
#include <blah>
(with angle bracktes<>
) the compiler looks in the default include path. You need to put the Qt include directory into the include path for your project. I'm not sure how this is done in Code::Blocks. It's probably somewhere in the project settings.