Header location issues while porting Qt code from Windows to Ubuntu - c++

I'm trying to port code written in Qt on Windows to Qt on Ubuntu. The problem I'm facing is that it gives me this error for my ui_windowform.h header:
error: QtWidgets/QApplication: No such file or directory
I searched on Google for solutions but didn't find anything relevant. I've also added INCLUDEPATH += $QTDIR/include/qt4/QtGuito .pro file.

I mostly of agree with LukasT, but Qt 4 does still have QApplication, however it is located in a slightly different location :) .... or maybe :(
You should find it here: .../qt4/QtGui/QApplication .... or somthing like that, I can't quite recall now...
But I would definatley try to keep your Qt version the same on each platform then you garantee that you will have no Qt lib issues... compiler on the other hand is not garanteed :o (but I would not worry too much about that)

It looks like the original Qt code uses Qt5, QtWidgets/QApplication rings the bell from me [1] and you are pointing to Qt4 in Ubuntu. You should try to install Qt5 in Ubuntu.
[1] http://qt-project.org/doc/qt-5.0/qtwidgets/qtwidgets-index.html

Related

Cannot run Qt Creator GUI outside of Qt. "The application was unable to start correctly (0xc000007b)" error

I downloaded C++ code from GitHub to tag images for training an object detector using Machine Learning.
Within Qt Creator 4.2.1 Based on Qt 5.8.0 (MSVC 2015, 32bit), I was able to compile and run the code. Unfortunately, I was not able to run the .exe outside of Qt Creator.
Initially, I received an error that
"The program can't start because libgcc_s_dw2-1.dll is missing".
Thanks to
QT The program can't start because libgcc_s_dw2-1.dll is missing, that was fixed easily by adding
"QMAKE_LFLAGS += -static"
to the .pro file. Now, when I run it I get
"The application was unable to start correctly (0xc000007b). Click OK to close the application."
I was able to reproduce the error using the simple "Hello World" default project that appears when you create a Qt Widget Application. This led me to believe something was wrong with my installation.
Based on the advice of this article: https://stackoverflow.com/questions/12099117/32-bit-qt-application-on-win-7-x64-wont-run-but-runs-fine-from-qt-creator, I used Dependency Walker to identify possible causes. I expected to see only a few items that I can follow up on. Instead, I received a list of close to 100 missing .dll files. All the files started with
"API-MS-WIN ###.DLL" or "EXT-MS ###.DLL"
where ### represent some additional text characters, for example;
"API-MS-WIN-SHCORE-STREAM-WINRT-L1-1-0.DLL"
I'm attaching a sample output.
Another suggestion was to copy over
libwinpthread-1.dll, libstdc++-6.dll, libgcc_s_dw2-1.dll.
That did not work either.
My next move was to simply get the latest version of QT and wish for the best. I installed Qt Creator 4.8.1 Based on At 5.12.0 (MSVC 2015, 32 bit). This time, I could not even get the code to run in the IDE. I received 1000+ error messages!
Based on advice from several pages, I added
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
to the .pro file and it still would not compile.
Also, I verified that the application is being built as a 32bit application. I'm running on a 64 bit Windows 10 system.
If anyone would like to take a crack at it to see if they can create a working .exe, here is the link: github.com/clavicule/BBTag
Qt provides a tool to copy the necessary dlls to the folder of your executable.
The tools is called windeployqt.exe and comes with your Qt installation. For me it is located at C:\Qt\5.9.1\msvc2015_64\bin\windeployqt.exe. You will have to look at your installation path and probably the msvc_32 folder to find it.
Then you go to the folder with your executable in it, oben a command prompt or powershell and execute path\to\windeployqt.exe yourProgram.exe and it will automatically copy the necessary dll files to this folder. Afterwards you can run your program without issues.
The official documentation for the tool can be found here.
Alternative 1: While developing you could use QtCreator which automatically adds the paths to the dlls when running your program - make sure to include them if you deploy your program!
Alternative 2: Add the path to the necessary dlls to your PATH variable. This isn't recommended either, since everyone who gets your program would have to do the same to run it.
I figured it out! My installation of Anaconda (a Python distribution popular for data science and machine learning) is the culprit.
From: #remy-lebeau
The application was unable to start correctly (0xc000007b)
The error:
"The application was unable to start correctly (0xc000007b) ..."
is a good indicator that the 32-bit app tried to load a 64-bit DLL. At first, this did not make sense since I verified many times that I was using the 32 bit version of Qt.
It turns out that the installation of the 64 bit version of Anaconda also contained many Qt5 dlls used for the PyQt5 package. Since the path to this folder came before the path to my c:\Qt...\bin folder, it was used in the build instead of the actual 32 bit version installed with Qt. This was not obvious because I was unaware of PyQt5 so I had no idea that it came with Anaconda. A simple reordering of the path entries using the System Environment Variables interface AND a system restart fixed the problem.
Silver lining: I now know C++ and designing GUIs w/ QT and PyQt5
Thanks #albertmand and #jwernerny

OpenCV in Code::Blocks: The application was unable to start correctly (0xc00000be)

I set up OpenCV with Code::Blocks as per this tutorial: http://kevinhughes.ca/tutorials/opencv-install-on-windows-with-codeblocks-and-mingw/.
I've got as far as building the test program at the end successfully, but when I try to run it I get the following error: "The application was unable to start correctly (0xc00000be). Click OK to close the application."
The one thing that is certainly different from the tutorial for me is that I'm working with OpenCV 3.0.0, Code::Blocks 13.12 and the latest version of mingw (number not obvious from their website or the installer).
I found that other people had had this problem in the past, e.g. The application was unable to start correctly (0xc00000be)
However, it has been a long time since that thread was active, I'm working with newer versions of the software and, most importantly, the answer given there didn't help (I compiled openCV with the same mingw that I'm using with Code::Blocks), so I thought this question would be worth asking (sorry if it's not, I'm rather new to this).
Could anybody suggest a fix that might get rid of this error?
A few other things to note:
I didn't download the Code::Blocks that came with mingw as I was advised against it, I got them separately as per the tutorial
I have installed OpenCV and Code::Blocks on my E: drive, though mingw is still on my C:.
I have added both mingw and OpenCV to my PATH variable, and mingw to my Path variable
I have linked the libraries in both the main compiler settings for Code::Blocks and the Build Options of my project.
I'm working from a 64-bit Windows 7 Laptop, but I have done everything 32-bit style as advised in the tutorial.
Thanks in advance!
So, one solution I've found to this problem is to copy all the .dll files from "...\opencv\build\x86\mingw\bin" to the project file (build directory).
Having done that, the project will run fine. This still doesn't (directly) explain why it wont run without those files (at least, several sources including the tutorial imply it should), and so isn't really optimal. I will continue to look for a solution for this so I don't have to clutter every opencv project I make with the .dlls.
However, for anyone simply wanting to get stuck into coding who is having this problem, I recommend that solution.

1.Project ERROR: Unknown module(s) in QT: webkitwidgets

Well, I was trying to use QWebView. As I learned from the internet, I should, and also this line webkitwidgets in .pro file after QT +=. So I added it and get this error:
Project ERROR: Unknown module(s) in QT: webkitwidgets
I know that a lot of people already asked about this error, but most of the answers were to install libqt5webkit5-dev using this command line: sudo apt-get install libqt5webkit5-dev.
The problem is, that I am on Windows, not on Linux, so this can't be useful for me.
The weird thing is, that I have Qt5WebKitWidgets.dll and Qt5WebKit.dll in C:\Qt\Tools\QtCreator\bin, so I suppose, that I have everything I need to use QWebView and to add this line QT += webkitwidgets without getting any errors.
Also, I learned that WebKitWidgets is no longer supported after QT 5.0 and newer(or something like that), and I should use QtWebEngine, but I don't understand how to use it in Qt Widgets Application with QWebView.
You're mixing up Qt Creator (an IDE) and Qt — the development toolkit itself. It absolutely doesn't matter what's bundled with Qt Creator — whatever is there is used solely by Qt Creator since it is also built using Qt.
You need to look in your Qt's installation directory, under mkspecs/modules. Each module has a .pri file. You should see both qt_lib_webkit.pri and qt_lib_webkitwidgets.pri. If you don't, that would mean that the modules weren't built for the Qt that you're using. The modules folder is where qmake looks for Qt module definitions.
If you're using a prebuilt recent version of Qt, it's likely that it is built with WebKit turned off. The workaround would be to go to a previous minor version (say 5.4 instead of 5.5), or to build Qt yourself.
Similar to Kuba Ober's answer, I got it to work by copying the webkit and webkitwidgets pri files from a previous installation, 5.5.
~/Qt/5.5/clang_64/mkspecs/modules/
The weird thing is, that I have Qt5WebKitWidgets.dll and Qt5WebKit.dll in C:\Qt\Tools\QtCreator\bin, so I suppose, that I have everything I need to use QWebView and to add this line QT += webkitwidgets without getting any errors.
Thats because windows dlls must be on the path or on the base path of the app, is just the way of windows of doing things. You can see that if you install qtcreator on windows, the app will be without dlls on the lib folder. Everything will be on the bin folder

Qt Libraries are not included

I checked if the question exists but it doesn't seem to help me. I'm clearly new to Qt, i installed Qt Creator 5.4 in my Windows 7 Ultimate. I installed everything Qt 5.4 provides and also installed MinGW 4.9.1. The problem is when i open a console application project it immediately gives these errors. I tried different projects and error is the same.
Project ERROR: Unknown module(s) in QT: core
I tried to check intellisense for include and it didn't show ANY library to me.
When i hover to include it gives : QCoreApplication: No such file or directory
I highly doubt Qt can't find it's own libraries. How can i show it to QtCreator ?
Additional info : Run button and everything related to run is disabled.
Any help will be appreciated, thanks :)
Maybe your project's path contains non ASCII characters.
Try a new project somewhere like C:\MyApp

Qt is unable to detect printers on Windows

I'm using Qt for a project (Qt 5.0.2, precompiled and downloaded from qt-project.org) on Windows 7 (32-bit) and I'm having trouble trying to print a document.
qDebug() << QPrinterInfo::availablePrinters().size(); // 0
I'm able to print as PDF and I tested the same executable in other computers, it works just well. I do have printers installed and I can print normally from any other program such as notepad or Word. Any clue on why is it returning an empty list? I can't find this behavior documented anywhere, is this a Qt bug?
When you deploy your Qt application, you should put
[your Qt application]\printsupport\windowsprintersupport.dll
The library windowsprintersupport.dll should be taken from
[Qt path]\[platform]\plugins\printsupport
P.S. The first answer is almost correct, except path's names.
May be your application cannot find plugins which allow printing
facilities (printingsupport directory must be in execution directory
from qt the bin\plugins directory).
This answer is moved from AnatolyS' comment.