Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problem in Visual Studio 2019: "cannot open source file ui_*.h"
Forum Update on Monday, May 27th 2025

Problem in Visual Studio 2019: "cannot open source file ui_*.h"

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 4 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CJha
    wrote on 1 Jul 2020, 12:45 last edited by
    #1

    Hi! I am new to C++, Qt, and Visual Studio. I have made a few small applications in Qt creator for practice. When I use Visual Studio 2019 and create a new Qt Widgets Application the mainWindow class's header file looks something like this:

    #pragma once
    #include <QtWidgets/QMainWindow>
    #include "ui_mainWindow.h"
    
    class mainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        mainWindow(QWidget *parent = Q_NULLPTR);
    
    private:
        Ui::mainWindowClass ui;
    };
    

    The Visual Studio tells me that there is a problem (shown below as comments) with these two lines in the above code:

    #include "ui_mainWindow.h" // Problem: cannot open source file "ui_mainWindow.h"
    Ui::mainWindowClass ui; // name followed by '::' must be a class or namespace name
    

    This happens every time I add a new form/window. Strangely enough, after I close the solution and reopen it then this problem usually disappears. I searched a lot for this problem on google as well as on Qt Forum and found no proper description and especially no way to fix this problem. From all my search this is all that I could understand:

    • This problem is because Qt designer uses qmake while Visual Studio uses CMake
    • ui_*.h files are automatically generated during build,
    • ui_*.h files are how *.ui form files are translated into C++ files for Visual Studio

    Till the time Visual Studio is unable to understand these two commands, the autocomplete feature doesn't work which is a big pain while programming. I am the type of person who likes to keep everything working smoothly and I would go to any extent to fix this problem permanently, but I don't know how to get it done. If you can then please help me fix this problem. Thanks :)

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 2 Jul 2020, 10:11 last edited by VRonin 7 Feb 2020, 10:13
      #2

      It's an issue relating to the VS Tools addin and its usage of uic. I normally fix it by changing back and forth between the 32bit and 64bit version of the project (using the Qt Project properties context menu option). It's annoying but it's berable once you get used to it.

      This problem is because Qt designer uses qmake while Visual Studio uses CMake

      VS does not use CMake. Qt Creator can use both qmake and CMake

      ui_*.h files are automatically generated during build,

      Correct but the problem arises from the timing of its creation

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply 2 Jul 2020, 18:20
      4
      • V VRonin
        2 Jul 2020, 10:11

        It's an issue relating to the VS Tools addin and its usage of uic. I normally fix it by changing back and forth between the 32bit and 64bit version of the project (using the Qt Project properties context menu option). It's annoying but it's berable once you get used to it.

        This problem is because Qt designer uses qmake while Visual Studio uses CMake

        VS does not use CMake. Qt Creator can use both qmake and CMake

        ui_*.h files are automatically generated during build,

        Correct but the problem arises from the timing of its creation

        C Offline
        C Offline
        CJha
        wrote on 2 Jul 2020, 18:20 last edited by
        #3

        @VRonin Thanks! Changing between 32bit and 64bit versions seems to do the trick faster than what I was doing before.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marcio Barcellos
          wrote on 21 Dec 2020, 03:25 last edited by
          #4

          My solution: since header files are generated at $(IntDir)uic\ (see Qt User Interface Compiler -> Output Directory) I've added that to C/C++ -> General -> Additional Include Directories.

          J 1 Reply Last reply 21 May 2022, 09:37
          1
          • M Marcio Barcellos
            21 Dec 2020, 03:25

            My solution: since header files are generated at $(IntDir)uic\ (see Qt User Interface Compiler -> Output Directory) I've added that to C/C++ -> General -> Additional Include Directories.

            J Offline
            J Offline
            jmdvella
            wrote on 21 May 2022, 09:37 last edited by
            #5

            @Marcio-Barcellos Thank you! After days of troubleshooting this finally worked:

            $(IntDir)uic\ (see Qt User Interface Compiler -> Output Directory) I've added that to C/C++ -> General -> Additional Include Directories.

            Im a novice so I dont know what its actually doing but thank you for getting me through this first hurdle!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved