简体   繁体   English

带QT的Visual Studio无法编译GUI类

[英]Visual Studio with qt fails to compile gui class

I have recently found this tool that allows to use qt within visual studio so I wanted to give it a try. 我最近发现该工具允许在Visual Studio中使用qt,所以我想尝试一下。 Click here to see which tool I used. 单击此处查看我使用的工具。

So I just installed that tool and of course install qt (version 5.11.0), then in Visual Studio a new menu appears referring to qt in which I have to set up the path to include qt. 因此,我只安装了该工具,当然也安装了qt(版本5.11.0),然后在Visual Studio中出现了一个新菜单,引用了qt,我必须在其中设置包含qt的路径。 Before that, in the installation of qt I must specify also to install the integration with visual studio 2017 (its not default) and this way I can set up the path. 在此之前,在安装qt时,我还必须指定安装与Visual Studio 2017的集成(它不是默认设置),这样我可以设置路径。

Here is the options of qt in visual studio 这是Visual Studio中的Qt选项

Now is when the problems begin, I created a qt project and tried to compile, it works fine with no problem at all. 现在是问题开始的时候,我创建了一个qt项目并尝试进行编译,它工作正常,没有任何问题。 But then I tried to add a GUI class with the assistant and compile again, in this case some errors appear related with unresolved external symbols. 但是随后我尝试使用助手添加GUI类并再次进行编译,在这种情况下,出现一些与无法解析的外部符号有关的错误。

Visual Studio errors Visual Studio错误

There is also a warning in the gui class with Q_OBJECT, after some research I found that this might be the problem but since its my first time with qt I have no idea. 经过研究后,我在gui类中使用Q_OBJECT发出警告,这可能是问题所在,但是自从我第一次使用qt以来,我一无所知。

This is the code of the GUI class I created. 这是我创建的GUI类的代码。

#pragma once

#include <QtWidgets/qwidget.h>
#include <GeneratedFiles/ui_WindowTFG.h>

class WindowTFG : public QWidget
{
    Q_OBJECT

public:
    WindowTFG(QWidget *parent = Q_NULLPTR);
    ~WindowTFG();

private:
    Ui::WindowTFG ui;
};

This is my version of visual studio and qt. 这是我的Visual Studio和Qt版本。 Visual Studio 2017 15.7.1 - Qt 5.11.0 Visual Studio 2017 15.7.1-Qt 5.11.0

If anybody can point me out to the right direction I would be grateful. 如果有人能指出我正确的方向,我将不胜感激。

Okay, since nobody seems to know where the problem is im gonna update the situation just in case it could be useful for somebody. 好的,因为似乎没人知道问题出在哪里,以防万一它可能对某人有用。

I could not compile my project but I found a "way" for using qt in visual studio, in the moment that you create a qt project in visual studio I selected "qt console application", well, instead of that option I tried "qt GUI application" which already creates a project with a GUI class. 我无法编译我的项目,但是我发现了在Visual Studio中使用qt的“方法”,在您在Visual Studio中创建qt项目的那一刻,我选择了“ qt控制台应用程序”,而不是尝试了“ qt GUI应用程序”,该应用程序已经使用GUI类创建了一个项目。 This time I could compile my project and use it as usual, the difference with the class which I could not compile is a file with extension ".qrc" (besides .h, .cpp and .ui files) so my guess is that because of that missing file my previous project was not working properly. 这次我可以像往常一样编译项目并使用它,与无法编译的类的区别是扩展名为“ .qrc”的文件(.h,.cpp和.ui文件除外),所以我的猜测是因为丢失的文件中,我以前的项目无法正常工作。

Hope this could be useful for somebody with similar problems. 希望这对有类似问题的人有用。

I will leave this question unresolved for a time in case another user can explain this. 我会暂时解决这个问题,以防其他用户可以解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM