Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5.11 VS17 "Object reference not set to an instance of an object" issue
QtWS25 Last Chance

Qt5.11 VS17 "Object reference not set to an instance of an object" issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
visualstudioc++qtplugin
11 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.
  • G Offline
    G Offline
    Gilad Reich
    wrote on 4 Aug 2018, 23:28 last edited by
    #1

    Hey everyone,
    I'm trying to get static linking with qt under visual studio 2017 and getting this error message that I wrote in the title.
    I'm using Qt5.11.1 version. this error occurs even with fresh new project.
    Note that I built Qt from source with static linking, so here are my steps:

    1. Opening Visual Studio 2017 Developer Command Prompt.
    2. cd Qt\Qt5.11.1\5.11.1\Src
    3. SET _ROOT=C:\projects\tools\Qt\Qt5.11.1\5.11.1\Src
    4. SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
    5. configure -platform win32-msvc -static -debug-and-release -opensource -nomake examples -nomake tests
    6. jom
    7. When build finish, opening Visual Studio 2017.
    8. Now in VS qt plugin, I go to: Qt VS Tools -> Qt Options -> Add and then in Version Name: msvc-static and in Path I set:
      C:\projects\tools\Qt\Qt5.11.1\5.11.1\Src\qtbase
    9. Now I go head and create new Qt GUI project: File -> New -> Project -> Qt GUI Application.

    Now when I click on create, it throws this error:
    "Object reference not set to an instance of an object"
    My Qt Visual Studio Plugin version is 2.2.1.

    Am I doing something wrong? reading the documentation and seeing some videos in YouTube, I see it worked for them, but they use older Qt versions of course as this videos made in 2014.
    What is also strange, that even tho when I specified in my configure command -debug-and-release, I look under the lib folder and I see only release libraries and not debug, i.e I see Qt5Gui.lib and not also Qt5Guid.lib :/ same happens when I tried to configure only -debug, it still builds the Release version.

    Another question I've regarding static linking in visual studio, I know when I do static linking I lose the ability to use plugins and in the main.cpp I need to add this to get it work:
    #include <QtPlugin>
    Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);

    Now something that I'm quiet curious, it doesn't conflicts with visual studio configuration where by default it set under Project Settings -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library to Multi-threaded DLL(/MD) ?
    Will it still do static compilation even though visual studio configurations clearly states that the application will be compiled with dynamic linking?

    Would really appreciate some help, as I've been spending quiet some time on this. Thanks in advance!

    K 1 Reply Last reply 5 Aug 2018, 09:49
    0
    • G Gilad Reich
      4 Aug 2018, 23:28

      Hey everyone,
      I'm trying to get static linking with qt under visual studio 2017 and getting this error message that I wrote in the title.
      I'm using Qt5.11.1 version. this error occurs even with fresh new project.
      Note that I built Qt from source with static linking, so here are my steps:

      1. Opening Visual Studio 2017 Developer Command Prompt.
      2. cd Qt\Qt5.11.1\5.11.1\Src
      3. SET _ROOT=C:\projects\tools\Qt\Qt5.11.1\5.11.1\Src
      4. SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
      5. configure -platform win32-msvc -static -debug-and-release -opensource -nomake examples -nomake tests
      6. jom
      7. When build finish, opening Visual Studio 2017.
      8. Now in VS qt plugin, I go to: Qt VS Tools -> Qt Options -> Add and then in Version Name: msvc-static and in Path I set:
        C:\projects\tools\Qt\Qt5.11.1\5.11.1\Src\qtbase
      9. Now I go head and create new Qt GUI project: File -> New -> Project -> Qt GUI Application.

      Now when I click on create, it throws this error:
      "Object reference not set to an instance of an object"
      My Qt Visual Studio Plugin version is 2.2.1.

      Am I doing something wrong? reading the documentation and seeing some videos in YouTube, I see it worked for them, but they use older Qt versions of course as this videos made in 2014.
      What is also strange, that even tho when I specified in my configure command -debug-and-release, I look under the lib folder and I see only release libraries and not debug, i.e I see Qt5Gui.lib and not also Qt5Guid.lib :/ same happens when I tried to configure only -debug, it still builds the Release version.

      Another question I've regarding static linking in visual studio, I know when I do static linking I lose the ability to use plugins and in the main.cpp I need to add this to get it work:
      #include <QtPlugin>
      Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);

      Now something that I'm quiet curious, it doesn't conflicts with visual studio configuration where by default it set under Project Settings -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library to Multi-threaded DLL(/MD) ?
      Will it still do static compilation even though visual studio configurations clearly states that the application will be compiled with dynamic linking?

      Would really appreciate some help, as I've been spending quiet some time on this. Thanks in advance!

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 5 Aug 2018, 09:49 last edited by
      #2

      @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

      Now when I click on create, it throws this error:
      "Object reference not set to an instance of an object"

      Post the complete error please. I imagine this is thrown by the compiler so you'd need to fix your code.

      I know when I do static linking I lose the ability to use plugins and in the main.cpp I need to add this to get it work

      No you lose the ability to load the automatically, which is why the preprocessor magic is required.

      Read and abide by the Qt Code of Conduct

      G 1 Reply Last reply 5 Aug 2018, 10:25
      1
      • K kshegunov
        5 Aug 2018, 09:49

        @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

        Now when I click on create, it throws this error:
        "Object reference not set to an instance of an object"

        Post the complete error please. I imagine this is thrown by the compiler so you'd need to fix your code.

        I know when I do static linking I lose the ability to use plugins and in the main.cpp I need to add this to get it work

        No you lose the ability to load the automatically, which is why the preprocessor magic is required.

        G Offline
        G Offline
        Gilad Reich
        wrote on 5 Aug 2018, 10:25 last edited by
        #3

        @kshegunov said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

        Post the complete error please. I imagine this is thrown by the compiler so you'd need to fix your code.

        That's the funny thing with this error from Microsoft side, it makes zero sense and doesn't give you any information.
        I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

        K 1 Reply Last reply 5 Aug 2018, 12:23
        0
        • G Gilad Reich
          5 Aug 2018, 10:25

          @kshegunov said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

          Post the complete error please. I imagine this is thrown by the compiler so you'd need to fix your code.

          That's the funny thing with this error from Microsoft side, it makes zero sense and doesn't give you any information.
          I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 5 Aug 2018, 12:23 last edited by
          #4

          @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

          I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

          Does it come up when you compile said project, or something else?

          I'd expect this error to come from code like this:

          SomeClass object;
          
          SomeClass & ref; //< Not set
          
          ref = object; //< No can do, not allowed in C++
          

          Read and abide by the Qt Code of Conduct

          G 1 Reply Last reply 5 Aug 2018, 14:50
          1
          • K kshegunov
            5 Aug 2018, 12:23

            @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

            I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

            Does it come up when you compile said project, or something else?

            I'd expect this error to come from code like this:

            SomeClass object;
            
            SomeClass & ref; //< Not set
            
            ref = object; //< No can do, not allowed in C++
            
            G Offline
            G Offline
            Gilad Reich
            wrote on 5 Aug 2018, 14:50 last edited by
            #5

            @kshegunov said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

            @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

            I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

            Does it come up when you compile said project, or something else?

            I'd expect this error to come from code like this:

            SomeClass object;
            
            SomeClass & ref; //< Not set
            
            ref = object; //< No can do, not allowed in C++
            

            It just shows up as soon as I create a fresh new GUI application project and then it fails to do all the configurations and stuff. I'm assuming it has to do something with the requirement of Qt VS Tools plugin that requires certain things that aren't automatically transferred into the build folder when I build Qt with static linking. I'll try and debug this issue.

            K 1 Reply Last reply 5 Aug 2018, 14:57
            0
            • G Gilad Reich
              5 Aug 2018, 14:50

              @kshegunov said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

              @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

              I'm not sure exactly where do I find the full error, but that's the only thing that comes up as soon as I create a fresh new project.

              Does it come up when you compile said project, or something else?

              I'd expect this error to come from code like this:

              SomeClass object;
              
              SomeClass & ref; //< Not set
              
              ref = object; //< No can do, not allowed in C++
              

              It just shows up as soon as I create a fresh new GUI application project and then it fails to do all the configurations and stuff. I'm assuming it has to do something with the requirement of Qt VS Tools plugin that requires certain things that aren't automatically transferred into the build folder when I build Qt with static linking. I'll try and debug this issue.

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 5 Aug 2018, 14:57 last edited by
              #6

              @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

              certain things that aren't automatically transferred into the build folder when I build Qt with static linking.

              I'm rather far from the windows world, but how do you mean? Usually, it's just enough to point the IDE you use to the qmake binary (as a build step) and qmake takes care of the paths and such; no copying required is what I mean.

              Read and abide by the Qt Code of Conduct

              G 1 Reply Last reply 5 Aug 2018, 15:11
              0
              • K kshegunov
                5 Aug 2018, 14:57

                @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

                certain things that aren't automatically transferred into the build folder when I build Qt with static linking.

                I'm rather far from the windows world, but how do you mean? Usually, it's just enough to point the IDE you use to the qmake binary (as a build step) and qmake takes care of the paths and such; no copying required is what I mean.

                G Offline
                G Offline
                Gilad Reich
                wrote on 5 Aug 2018, 15:11 last edited by
                #7

                @kshegunov said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

                @Gilad-Reich said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

                certain things that aren't automatically transferred into the build folder when I build Qt with static linking.

                I'm rather far from the windows world, but how do you mean? Usually, it's just enough to point the IDE you use to the qmake binary (as a build step) and qmake takes care of the paths and such; no copying required is what I mean.

                Yea, that's exactly what I expected from it to do, but it seems like with the new version something needs to be patched in Qt VS Tools side or the actual build process of the latest Qt version.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gilad Reich
                  wrote on 5 Aug 2018, 18:41 last edited by
                  #8

                  Ok! I think I found out the source of the problem!
                  In:

                  C:\Qt\Qt-5.11.1\mkspecs
                  

                  There is a file that gets called when I create new project in visual studio called:

                  qconfig.pri
                  

                  This is how this file looks like in the official Qt installation:

                  QT_ARCH = i386
                  QT_BUILDABI = i386-little_endian-ilp32
                  QT.global.enabled_features = shared debug_and_release build_all c++11 future concurrent
                  QT.global.disabled_features = cross_compile framework rpath appstore-compliant c++14 c++1z pkg-config force_asserts separate_debug_info simulator_and_device static
                  QT_CONFIG += shared debug_and_release debug release build_all c++11 concurrent dbus no-pkg-config stl
                  CONFIG += shared release no_plugin_manifest
                  QT_VERSION = 5.11.1
                  QT_MAJOR_VERSION = 5
                  QT_MINOR_VERSION = 11
                  QT_PATCH_VERSION = 1
                  QT_MSVC_MAJOR_VERSION = 19
                  QT_MSVC_MINOR_VERSION = 0
                  QT_MSVC_PATCH_VERSION = 24215
                  QT_EDITION = OpenSource
                  QT_LICHECK = licheck.exe
                  QT_RELEASE_DATE = 2018-06-18
                  

                  This configuration file is the stable one and doesn't break a project creation in Visual Studio.
                  Now I'll show how the configuration file that breaks looks like in the compiled version of Qt that I wanted to build with static linking:

                  QT_ARCH = i386
                  QT_BUILDABI = i386-little_endian-ilp32
                  QT.global.enabled_features = debug_and_release build_all c++11 future concurrent static
                  QT.global.disabled_features = cross_compile framework rpath shared appstore-compliant c++14 c++1z pkg-config force_asserts separate_debug_info simulator_and_device
                  QT_CONFIG += debug_and_release release debug build_all c++11 concurrent dbus no-pkg-config release_tools static stl
                  CONFIG += debug no_plugin_manifest static
                  QT_VERSION = 5.11.1
                  QT_MAJOR_VERSION = 5
                  QT_MINOR_VERSION = 11
                  QT_PATCH_VERSION = 1
                  QT_MSVC_MAJOR_VERSION = 19
                  QT_MSVC_MINOR_VERSION = 14
                  QT_MSVC_PATCH_VERSION = 26433
                  QT_EDITION = OpenSource
                  

                  Now the line that actually breaks here is the:

                  CONFIG += debug no_plugin_manifest static
                  

                  If you look at the official configuration file, it set to:

                  CONFIG += shared release no_plugin_manifest
                  

                  Now if I change this row in the custom one, I can create a qt project in Visual Studio and I won't get this exception.
                  So I was playing around with the options there to see if I can change from shared to static and it still breaks when I create new visual studio project.
                  I tried the following options separately and they all break unfortunately:

                  CONFIG += debug no_plugin_manifest static
                  CONFIG += static debug no_plugin_manifest
                  CONFIG += static release no_plugin_manifest
                  CONFIG += static debug_and_release no_plugin_manifest
                  CONFIG += static
                  CONFIG += static debug
                  CONFIG += static release
                  CONFIG += static debug_and_release
                  

                  I hope it gives a better idea why this error appears and someone can look at this.
                  P.S: Is "Miguel Costa" or "Karsten Heimrich" who worked on the Qt VS Tools available here? or maybe someone that is involved, or anyone that has an idea/suggestion?
                  Thanks a lot!

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Gilad Reich
                    wrote on 5 Aug 2018, 19:26 last edited by
                    #9

                    Another update :) I just tried static linking with Qt Creator based on Qt 5.11.1 (MSVC 2015, 32 bit) and it works. I can compile the application with static linking just by adding static to the config file.
                    Which kind of tells us, that from building qt with static linking from source everything is fine, just that something is definitely wrong with Qt VS Tools. so it kind of closes another corner for us.

                    1 Reply Last reply
                    1
                    • G Offline
                      G Offline
                      Goddard
                      wrote on 8 Sept 2019, 00:15 last edited by
                      #10

                      I have this issue as well and nothing works. Just trying to import an existing project.

                      JKSHJ 1 Reply Last reply 8 Sept 2019, 08:06
                      0
                      • G Goddard
                        8 Sept 2019, 00:15

                        I have this issue as well and nothing works. Just trying to import an existing project.

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on 8 Sept 2019, 08:06 last edited by
                        #11

                        @goddard said in Qt5.11 VS17 "Object reference not set to an instance of an object" issue:

                        I have this issue as well and nothing works. Just trying to import an existing project.

                        Go to Extensions > Qt VS Tools > Qt Options, and add a valid Qt Version.

                        See https://bugreports.qt.io/browse/QTVSADDINBUG-647

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        1

                        • Login

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