Porting Qt4 to Qt5: unresolved external symbols - c++

Qt5 is the new generation of Qt and it has some changes.
I have a project building well with Qt4. I've downloaded Qt5-VisualStudio2010 package and I'm trying to port my project from Qt4 to Qt5. Problems arise.
All 'include' paths have been fixed well. However, the compiler now reports hundreds of 'unresolved external symbols' (almost all function calls, sounds like the compiler can't find any .lib file). I even tried to add all .lib files found in the Qt SDK folder, but useless. The most basic class and method: QApplication::exec(...) also reported as 'unresolved symbol'.
The project file has been changed to fit Qt5 packaging:
myproject.pro file:
QT += widgets
Anyone have got similar experience with this new release of Qt?

From 'qt_newbie89' (http://qt-project.org/forums/viewthread/23200):
I have “accidentally” solved the problem. I rightclicked on the
project folder in the Project windows and choose qmake. After that,
choose Run and all the errors disappeared. I don’t know why that works
by the way.
From 'ChrisW67' (http://qt-project.org/forums/viewthread/23253/):
The Makefile file did not “become corrupted”: it was exactly as you
left it, full of commands and paths suitable for the previous Qt 4
installation. When Qt Creator ran nmake to build the project nmake did
not automatically re-run qmake to generate the Makefile because the
(untouched) Makefile was newer than the pro file that generated it.
This is normal and correct make behaviour, but it resulted in a
mismatch between your Qt5 in stall and expected Qt4 install.
My saying:
Yeah, that really solves the linking problem! The problem was actually that, when the project was created with Qt4, the 'make' file was also created along with the project nicely. When I removed Qt4, installed Qt5 and imported the old project by Qt5 (with new Qt Creator), possibly the 'make' file became corrupted.

I suspected that you would not be the only one who had this problem. Have you looked at: this yet? It talks about a PERL script in qt/base/bin called: fixqt4headers.pl. This is designed to fix the headers. I noticed another link which might help if that doesn't fix you up, try this, it looks to be fairly well thought out. And, no I haven't tried it. I haven't actually upgraded to Qt 5 yet. CHEERS!

This happened to me as well and I did following.
Additionally linked Qt5Widgetsd.lib
Changed the project property 'Treat Wchar_t as buil in' to true (at C++ -> Language section).

Related

Missing libgcc_s_seh-1.dll starting the .exe on Windows

Intro
I have a CMake-based C++ project. Until now I build and ran the project via CLion. Everything worked fine until I tried to run the .exe-file directly (not via CLion).
Problem
When I navigate to the cmake build directory in order to start my program via the executable file, it fails with the following message in the popup: Cannot continue the code execution because libgcc_s so-1.dll was not found. Reinstalling the program may resolve the issue.
I have the following questions
If I interpret the error message correctly, then this dll is missing on my computer. So I ask myself, why does my program still work when I start it via the development environment (CLion), although the error message expressly states that the source code requires this dll?
Is it the fault of my application/source code that the error appears or rather the current state of my computer? If the former, how can I prevent this error from appearing for other users?
What is the best way to fix this error? It's obvious that I need to download this dll, but where is the best place to put it (which directory and environment variable to use on Window)?
Which source is trustworthy to download this dll? I don't want to download any malware under this dll-name.
Optional: What kind of library is that? What functionalities does it offer?
Additional information
I use CMake as my build tool, CLion as the IDE and MinGW as the compiler.
What I have did so far?
I made sure it still works through the IDE.
I found this dll does not exist in the MinGW installation folder.
I searched the web for more information. Unfortunately, there are only pages unknown to me that only offer the download of this dll. That doesn't satisfy me.
I found the cause of my problem: I had two MingGW installations on my machine. Once the installation that comes with CLion and a separate one. The latter did not have the required dll. However, CLion used its own installation, which in turn owns the DLL. So the solution was to remove the separate installation and include the path to the CLion installation's bin/ directory in the PATH environment variable.
This file is part of MinGW-w64 when using SEH as exception model (as opposed to Dwarf or SJLJ). You need to distribute the .dll files your .exe file(s) depend on in the same folder as the .exe file(s).
If you don't have that file, then you probably have been using libraries compiled with different versions of GCC/MinGW(-w64). I recommend building everything with the same compiler to ensure stable binaries.
Tools like Dependency Walker can help you figure out which .dll files your .exe file depends on.
Or use the command line tool copypedeps -r from https://github.com/brechtsanders/pedeps to copy the .exe files along with it's dependencies.

Qt-Application Deployment doesn't work. Missing entry point and dll's

In the last months I created a project with the Qt-Creator version 4.7.0, Qt version 5.11.1 (open source version).
Now I tried to deploy it following the Qt doc and building the project with MSVC2017-64bit compiler as well as running windeployqt.exe afterwards on the generated executable.
As I tried to run the executable after the programm finished copying the neccessary dlls into the folder, a warning appeared:
The entry point ?
eventFilter#QAbstractItemView##MEAA_NPEAVQObject##PEAVQEvent###Z wasn't found in DLL "my/project/path/releasefolder/project.exe".
It seems to me like something was wrong with the Qt-Objects I use in my project, but I couldn't find anything, as it still worked flawlessly in the Qt-Creator.
A thought it might be due to the compiler having issues, so I changed it to mingw32, which I also tried to deploy the same way. But somehow in this case the warning disappeared, but many dlls were still missing even though windeployqt.exe should've already done that. And I also couldn't find them anywhere on my hard drive. I also tried a third compiler, but the issues weren't going away.
I searched online and only found people having problems with an entry point missing in a Qt dll or missing the Qt-Dlls in general, but haven't found anything related to my case.
I also tried Dependency Walker on every executable, but it found even more missing dll, which led me to believe the executables were somehow currupted so I tried it again and again, but with no success unfortunately.
Has someone any idea, why that could happen, or any suggestion for me?
Maybe I should change something in my project, even though it works fine in the IDE. I just need a way to deploy my Qt project in any way.
EDIT: Build using the Desktop Kit in Qt Creator with MSVC2017 the described warning appeared.
Build with Mingw32 (Desktop Kit) and with MSVC2017 using the UWP Kit in Qt Creator the following Dll was missing, that I haven't found anywhere on my hard drive: MSVCP140_APP.dll
EDIT2: I ended up downloading the required dll, to somehow get it to work, but it still didn't work. One build, that required that dll now started but immediately closes itself again and the other build was suddenly warning me of a missing procedure entry point.
EDIT [SOLUTION]: I let the Qt Creator create a whole new fresh project and copied all files from my old project in the new one. After that I only copied all the dll files into the folder and it worked.
Instead of relying on windeploy, manually add the dll. I am assuming you have built the project using mingw. Assuming you are using Qt 5.11.1, go to
C:\Qt\Qt5.11.1\5.11.1\\bin\ and copy all the dll files and paste in your executable folder. Also copy all directories from plugins folder (in /plugins) and paste in your folder. Now run the application, don't close the application. Now delete all the files from your executable folder. The one's not being used are deleted and the rest are left. I assume you are doing this on target computer. This might help.

Having trouble building Qt program

I created a Qt GUI application and I am trying to package it to share with other people. I built the package and used Dependency Walker to find all of the .dll files that I needed to include. After I put them all in the same directory as the .exe; I launched the .exe for the program and I got a message that another .dll was missing I included it. I was asked in the same way to add two more .dll files. After all the .dll's were included I launched the .exe and got this weird message.
I consulted Qt 5.0.2 documentation and I couldn't find any help. It works fine when I run it within Qt Creator.
I don't know what to do from here but any help would be great
Some things you could do to find out the problem:
Check if it behave the same way in debug and release mode. Note that the two modes need different DLLs.
Check if you are using the correct versions of the DLLs. If you installed different versions of Qt or other dependencies than there could be conflicts around DLLs that are the same but from different versions. Maybe you are in a kind of DLL Hell.
You should copy your program to another PC that doesn't have Qt installed. And watch if it works properly.

Qt moc failure without an error message

So I'm pretty new to Qt, and I've just inherited a project from someone else who is also new to Qt. He isn't around this week btw. We are using Visual Studio 2008, and have the latest version of Qt installed(4.6.2).
The project builds on my coworker's machine fine, and I can get the project from svn and build it directly. But under any other circumstances it refuses to build on my machine, and it doesn't give me much of an explanation why. Even if I just do a 'build clean' and then a 'build' it doesn't work. Any slight modification will make it fail.
When I try to build the entire project I get the error message:
1>Moc'ing MatrixTypeInterface.h...
1>moc: Cannot create
.\GeneratedFiles\Debug\moc_MatrixTypeInterface.cpp;.\GeneratedFiles\Debug\moc_matrixtypeinterface.cpp
1>Project : error PRJ0019: A tool
returned an error code from "Moc'ing
MatrixTypeInterface.h..."
The moc tool doesn't give any sort of error message as to why it isn't working, and I wasted most of yesterday trying to figure out why. I got the command that VS was using to call moc, and I entered in the command line myself. It didn't write anything to the screen.
Any ideas?
I finally found the answer. my coworker was back in the office today, and I used the build log off his machine to get his full moc command(about 4 lines long). Our moc commands were basically the same except at the very end. His command ended in:
-o ".\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp"
My command ended with:
-o ".\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp;.\GeneratedFiles\Debug\moc_matrixtypeinterface.cpp"
I checked the custom build step for that file, and removed the excess bit. After that the file compiled fine. I don't know how or why qt decided to add in this extra tidbit, but it did.
Thanks for your help guys. A couple of you suspected that it was a filesystem issue, and indeed a semicolon is not allowed in a windows filename. But I feel the root cause was Qt creating the wrong build string.
I'm accepting my own answer in the hope that it will help someone else.
It's most likely a filesystem error, you probably don't have a "GeneratedFiles" folder or don't have the correct permissions on it.
I have had issues where different versions of the moc and the add-in use "Generated" or "Generated Files" or "GeneratedFiles" for the folder. Check the settings on all the build steps.
Its possible that your .vcproj file is corrupted. I've had this issue before which resulted from having different versions of Qt and the Qt VS add-on ended up corrupting my .vcproj files. For a while, I had to manually fix the .vcproj file (My AdditionalDependencies="..." line was being swapped around and cut off for various header files that needed to be mocced, I was manually fixing these for every new header that needed to be mocced).
A clean reinstall of Visual Studios + Qt + Qt add-on ended up fixing this. Check your .vcproj file and see if its making sense.
Are you sure your file paths are correct and existing before moc runs? Since it appears that relative paths are provided to moc, I'd find out what moc's working directory is when it runs.
How was your .vcproj file generated? Was qmake used? Or cmake? Or was it by scratch?

QScintilla, example project doesn't work

I wanted to try QScintilla out. So i downloaded and installed it, no problems.
When i ran the example project it said I was missing QtCored4.dll, so i copied it into the directory, then it said it needed other dll's aswell so copied them too.
At the end it gives me a Visual C++ Runtime error. It just says it terminated in an unusual way.
I know this is vague, but this is just what is states, no additional error messages. The code is from the website, i didn't modify it.
Anyone has any clues about this?
Now that i have this problem, i thought maybe i should extend the standard Qt text component. And try to make my own component like QScintilla.
How hard can it be, to write a component like QScintilla? (Without looking at its source)
Update: So i loaded the example project under Qt Creator. Set the default config to release mode and let it run. And it worked. (very weird). If i switch to debug mode Qt Creator says:
Invalid parameter passed to C runtime function.
If i go to the directory in the file system ( not in Qt Creator ) and run the program (release mode), i get the strange errors i told you about in the comment. While if i run it from Qt Creator it works.
I have no problems with QScintilla. I have Qt 4.6 compiled from sources with VC++ 2008. After downloading QScintilla-gpl-2.4.1 and unpacking I compiled it with:
cd Qt4
qmake qscintilla.pro
nmake
and finally installed with
nmake install
copy %QTDIR%\lib\qscintilla2.dll %QTDIR%\bin
And while compiling and running example I have no problems.
So, first check you environment variables (My Computer, Right Click, Properties -> Advanced tab -> Environment Variables button). Check Path in System Variables section. I have %QTDIR%\bin (c:\Qt\qt-4.6.0\bin) in this variable.
Secondly I'm wondering about letter "d" in your message:
QtCored4.dll
If you made all steps described in documentation you will get release version of libraries and release version of example application linked against release version of Qt libraries. And not debug.
Finally may be QTextEdit & QSyntaxHighlighter is enough for your tasks. Check out Syntax Highlighter Example.
Response to comments.
It's some sort of well known problem (may be). So, as you can see you have 2 different folders with Qt libs
C:\Qt\2009.05\bin;C:\Qt\2009.05\qt\bin
in your path. Libraries in the first folder (...\bin) compiled with VS2008 and libraries in the second one (...\qt\bin) compiled with MinGW. The items in path variable are looked up when your application starts. Suddenly the folder with "wrong" libraries exists before the folder with correct item in your path variable. What you can do is to copy QtCore4.dll, QtGui4.dll and other libraries that you need to folder with your application executable. Hope this helps.
Some links about this problem:
#qtforum.org
#some blog post (in Russian =))