Qt5.11 VS17 "Object reference not set to an instance of an object" issue
-
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:- Opening Visual Studio 2017 Developer Command Prompt.
- cd Qt\Qt5.11.1\5.11.1\Src
- SET _ROOT=C:\projects\tools\Qt\Qt5.11.1\5.11.1\Src
- SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
- configure -platform win32-msvc -static -debug-and-release -opensource -nomake examples -nomake tests
- jom
- When build finish, opening Visual Studio 2017.
- 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 - 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!
-
@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.
-
@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. -
@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++
-
@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.
-
@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) andqmake
takes care of the paths and such; no copying required is what I mean. -
@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) andqmake
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.
-
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! -
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. -
@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.