0

I am trying to create a graphical application with QT, I would like to code it in VS Code. I had installed QT 6.0.2 with the QT Creator installer.

To compile the C++, I use mingw810_64 which is located here : C:/Qt/Tools/mingw810_64/bin/g++.exe

And so my libraries are located here : C:/Qt/6.0.2/mingw81_64/include/

I have well modified the file c_cpp_properties.json :

{
    "configurations": [
        {
            "name": "Win64",
            "includePath": [
                "${default}",
                "C:/Qt/6.0.2/mingw81_64/include/"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Qt/Tools/mingw810_64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
        }
    ],
    "version": 4
}

And so here is the simple program I am trying to compile for now:

#include <iostream>
#include <QtGui>

using namespace std;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget window;
    
    window.resize(320, 240);
    window.show();
    window.setWindowTitle(
        QApplication::translate("toplevel", "Top-level widget"));
    return app.exec();
}

Unfortunately, it seems that VS Code can't find the QtGui library and so I can't even compile my application

I thank you for your help !

Lolix Dudu
  • 313
  • 2
  • 15
  • 1
    Your header problem is that c_cpp_properties.json is for intellisense only. tasks.json is where you set the include directory for building. With that said, Qt will be difficult to do in your tasks.json alone. It won't call moc, rcc, uic ... You probably want to use the CMake tools extension and CMake to support Qt. – drescherjm Jul 18 '21 at 00:31
  • Ok, I never used CMake, here is what I did : https://pastebin.com/Sk6XT35B QT is well found, the version is the right one, but I don't really know what to do – Lolix Dudu Jul 18 '21 at 00:50
  • Your CMake looks fine to me. There is a CMake tools Extension for VSCode – drescherjm Jul 18 '21 at 03:26
  • I downloaded it, I did "configure" but there are still problems in the cpp where it does not find the library. Moreover I have the message "Found Qt 6.0.2" when I "configure". – Lolix Dudu Jul 18 '21 at 09:20
  • I have errors like "incomplete type not allowed" – Lolix Dudu Jul 18 '21 at 09:38
  • So I found, I had forgotten to include ```QApplication``` and ```QWidget```. Now I can compile my project but when I run the .exe, there is an error telling me that some dlls are missing (those of ```Qt6Core``` and ```Qt6Widdgets``` – Lolix Dudu Jul 18 '21 at 14:41
  • You can fix that by either setting your system `PATH` environment variable to contain the location of the dlls or putting the dlls in the same folder as the executable. You may also be able to modify your `launch.json` to set the `PATH` environment variable for debugging there. – drescherjm Jul 18 '21 at 14:47
  • It Works !!! Is it possible to add to the build the dll to transport the build to other devices? – Lolix Dudu Jul 18 '21 at 15:12
  • I have CMake create me a NSIS based install package but this can also be a solution [https://doc.qt.io/qt-5/windows-deployment.html](https://doc.qt.io/qt-5/windows-deployment.html) – drescherjm Jul 18 '21 at 15:16
  • Related to CPack / NSIS: [https://stackoverflow.com/questions/39260000/how-to-idiomatically-package-dependencies-for-a-qt-application-using-cpack](https://stackoverflow.com/questions/39260000/how-to-idiomatically-package-dependencies-for-a-qt-application-using-cpack) – drescherjm Jul 18 '21 at 15:19
  • @LolixDudu you can use windeployqt to copy all the necesary dlls into your programs folder just do on cmd promt ```windeployqt "path\tofolder\"``` , remember to be inside your qt mingw folder or it wont work, also can you show whats in your task.json? i cant link my qt librarys either – lightshadown Aug 30 '21 at 20:08

0 Answers0