Qt is unable to detect printers on Windows - c++

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.

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

Adding MinGW compiler to QT 5.6.0 Windows

I am a Total Noob at this and I know nearly nothing about this.
I just started using Qt Creator for windows 5.6.0 and While I wrote my first "Hello World" code..
I was asked to add a kit. I searched the net for similar issues and it said that I needed a compiler for Qt. Thus, I installed MinGW from QtForums
now when go to Tools->Options->Build&Run->compiler, I can not understand how do I add it to the list.
Please help me through it?
To just get started the easiest thing to do would be to go here:
Link to Qt downloads page
Scroll down and select Qt 5.6.0 for Windows 32-bit (MinGW 4.9.2, 1.0 GB) this will download the installer (its about 1 GB). Run it and choose all the default options. Then you will have Qt 5.6 with mingw and Qt Creator all setup ready to go.
Note: Before you start that its probably best to delete your current version - if you are not attached to it in any way :)
If you want to fix your current setup, then it might be longer-winded to find out what you are missing for mingw. For example you need the mingw qmake file that would be located here (using default install options):
C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\qmake.exe
to create your "Qt Version" part of the kit. And the actual mingw compiler, which is located here (using default install options):
C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\g++.exe
to create your compiler. Once you have both of these then you can put them together to create your new kit.
But to just add a compiler all you need to do is:
Click compilers tab
Click add and select mingw
A new compiler is added, click it
You will see some options below, add your compiler executable path in (like the one above for example).
And you are done - there are some other options, but you probably don't need to use them.
note my paths are for qt 5.5.1 (obviously) so slightly different to 5.6 :)
update
Its all been moved around! - here are the new paths:
offline-installers
old-version-archives
Well. I was unable to provide the data before but it all makes more sense now.
What I had installed was Qt for windows 64-bit (vs 2013, 836mb).
Hence, Instead of MinGW, I have msvc2013_64. It does have qmake.exe but doesnt have g++.exe. And I had downloaded it separately.
You're answer was very helpful.
Added MinGW packages to QT installation with the QT Maintenance Tool (C:\Qt\MaintenanceTool.exe)
It allows to add/remove components via the qt repositories. So no need for re-installation.

Qt deployment issue (MinGW inside)

I try to deploy a Qt app on a basic Windows 7 Pro SP1 machine.
My app works fine when I run it inside Qt Creator or on any machine with Qt insllated.
I have read a lot of posts and try many different things without success.
Things tried :
Windeploy Qt
Quick and dirty method of Qt Wiki
Add mingwm10.dll
Add libEGL.dll
Check loaded dll with dependency walker
Check loaded dll with Qt Creator debugger
My app crashes when I run it with these two error messages :
This application failed to start because it could not find or load the Qt platform plugin "windows".
This application has requested the runtime to terminate it in an unsual way. Please contact...
This is my current tree (obtained with windeployqt) :
*.exe
*.dll
platforms/qwindows.dll
imageformats/*.dll
iconengines/*.dll
With dependency walker, I have some red lines even if the app runs normally but nothing interesting.
Dev machine info :
Windows 7 Pro Sp1 64 Bits
Qt Creator 3.3.0
MinGW 4.9.1 32 Bits
Qt SDK 5.4.0
I'm probably doing something wrong but what ?!
The executable seems to search something in the Qt base directory because when I rename it the deployed app doesn't want to work anymore.
Need help please ;)
Ok, I found the solution...
I added this line at the very beginning of my main function :
QApplication::addLibraryPath("./");
After that, windeployqt does the job.
I hope it will help someone in the future.

This application failed to start because it could not find or load the Qt platform plugin "windows"

I tried making an executable file of my program but there are some errors which I did not understand or could not find solutions of. I used my .exe file onto another computer and there was an error. I made my program through QtCreator (v 5.1.1)with my Windows 7, 64-bit laptop. There was an error when I used it in 2 32-bit laptops.
The error message says:
This application failed to start because it could not find or load the Qt platform plugin "windows".
Available platform plugins are: minimal, offscreen, windows.
Reinstalling the application may fix the problem.
I already created a new folder called "platforms" containing "qminimal.dll", "qoffscreen.dll" and "qwindows.dll" in the same level of my .exe file. I also pasted in the same level the other DLLs that my program needs.
In Qt 5.2, there is a tool that can be used for deployment on Windows: windeployqt. It will be in the bin folder of your Qt installation. It greatly simplifies deployment, so if you don't mind downloading a newer Qt version, I'd highly recommend it. It may even work with an older Qt version, but I haven't tested it.
We had exact same problem with Qt5.3.
Problem arised when we've rebuilt the Qt to reduce dependencies (e.g. Qt5Positioning, Qt5Sensors).
Created dlls were copied to different directory (source for installation), but we forgot to copy also newly created platforms plugin dlls.
The problem was fixed by using all dlls from same Qt build (with same configuration).
Your problem is probably the same: mixing dlls from different Qt builds (e.g. different configuration, version,...).

Header location issues while porting Qt code from Windows to Ubuntu

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