如何编程C ++ 11使用Qt5? [英] How to Program C++11 Using Qt5?

查看:483
本文介绍了如何编程C ++ 11使用Qt5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备好与我的朋友一起编写跨平台项目。我们决定分别使用Qt和gcc作为我们的IDE和工具链。他在Linux上工作,我在Windows上工作。

I'm getting ready to program a cross-platform project with my friend. We decided on using Qt and gcc as our IDE and toolchain respectively. He works on Linux, I work on Windows.

但是,Linux上的gcc不一定是Windows上的gcc。更具体地说,Qt在Windows上安装mingw与gcc 4.4和我的朋友有gcc 4.7。所以我试图得到一个更新的gcc版本的Windows。

However, gcc on Linux isn't necessarily gcc on Windows. More specifically, Qt on Windows installs mingw with gcc 4.4 and my friend has gcc 4.7. So I tried getting a more recent gcc version for windows.

我当前的版本的Qt是5,并使用gcc 4.7从这个网站下载并安装:http://www.equation.com/servlet/equation.cmd?fa=fortran

My current version of Qt is 5 and using gcc 4.7 downloaded and installed from this site: http://www.equation.com/servlet/equation.cmd?fa=fortran

我将它安装在C:\QtSDK\mingw,只需要覆盖从Qt安装存在的所有文件。我想,如果我只是采取短路线,我不会重新配置任何Qt。

I installed it in C:\QtSDK\mingw and simply overrode all the files existing from the Qt installation. I figured that I wouldn't have to reconfigure anything in Qt if I just took the short route.

但是,即使使用编译器标志:

However, even using the compiler flags:

QMAKE_CXXFLAGS += -std=c++0x (Qt 4.7)

CONFIG   += c++11 (Qt5)

IDE或工具链无法编译一个简单的基于范围的for循环:

the IDE or toolchain fails to compile a simple range-based for loop:

int main(int argc, char *argv[])
{
    int my_array[5] = {1, 2, 3, 4, 5};
    for (auto x : my_array)
        std::cout << x << std::endl;

    return 0;
}

或初始化程序列表:

int main(int argc, char *argv[])
{
    QVector<int> testsData { 1, 2, 10, 42, 50, 123  };
    QStringList options = { QLatin1String("foo"), QLatin1String("bar")  };

    return 0;
}

然而,查看gcc 4.7的实现细节,和更多 - 应当容易获得。

However, looking at the implementation details of gcc 4.7, both of these features- and more- should be readily available.

有没有人试图在Windows上使用gcc和Qt?如果是,你是如何让它工作?我想要一个解决方案使用gcc 4.6或4.7,但如果不是可能的话,将解决较少。

Has anyone else tried to use gcc and Qt for Windows? If so, how did you get it to work? I would like a solution using gcc 4.6 or 4.7, but will settle for less if it is not at all possible.

或者,有一个开发环境为Linux和Windows使用C ++ 11的功能?如果它只是工作,我还会解决Qt之外的东西...

Alternatively, is there a dev environment for Linux and Windows that makes use of C++11 features? I would also settle for something besides Qt if it just works...

我使用的来源:

Qt中的C ++ 0x(Qt 4.7-4.8)

Qt5中的C ++ 11

推荐答案

QMAKE_CXXFLAGS += -std=c++0x

导致错误,因为您没有使用MinGW编译器。 D9002:忽略未知选项 -std = c ++ 0x 是MSVC编译器的错误。

Results in an error because you're not using the MinGW compiler. "D9002: Ignoring unknown option -std=c++0x" is an error from the MSVC compiler.

在QtCreator中,转到项目选项卡(左侧),并更改您使用的工具链。如果它没有自动检测MinGW,你将不得不自己添加它通过点击管理按钮。

In QtCreator, go to the projects tab(on the left) and change the toolchain you're using. If it hasn't auto-detected MinGW, you're going to have to add it yourself by clicking on the manage button.

这篇关于如何编程C ++ 11使用Qt5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆