I have been trying to play a simple audio file using:
http://qt-project.org/doc/qt-5/qmediaplayer.html and
http://qt-project.org/doc/qt-5/QSound.html
I am using Qt 5.3 but the problem is, when I type #include QMediaPlayer or QSound, QtCreator keeps underlining them with red because it can't find them. The thing is, the files are there. They are located in QtMultimedia/ and I have seen them. When I try to prefix QtMultimedia/QMediaPlayer or QtMultimedia/qmediaplayer.h it still can't find them.
If I type #include "QtMultimedia/" the auto-complete drop down in the text editor only shows QtMultimedia/QtMultimediaDepends. Normally you get a list of all the files in the folder but not with this one.
Looks like there is something wrong with the paths. How do I fix them? I am using a Windows machine.
Edit: I have included project settings - see screenshots.
I think, after you modified your .pro file, You didn't run the qmake.
build-> run qmake
qmake will generate the makefile you need to build the src code.
if you only change the .pro file, but didn't run it. Nothing is changed.
and that is reason, you create a new project and it is working.
Ok I figured it out. It's a problem with my Qt version.
My Qt 5.3 version is a custom compiled one. When I select the included version that came with the installer, QSound is found. When I change the kit to the custom compiled one, the file cannot be found. I must have forgotten to include some sort of multimedia option to the configure script during compilation.
Now the question is what is the missing option, I will need to do more reading...
Of course, comments and suggestions are welcome :)
You have to add the word 'multimedia' in your .pro file:
QT += core GUI
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets multimedia
Related
I am writing a very minimal C/C++ Qt-based application for Windows (only Windows -- not cross platform at all) that uses a VISA library (visa64.dll) to talk to some external hardware. That library, in turn, uses some other libraries:
(screenshot from Dependency Walker a.k.a. depends.exe)
Originally I wrote it in Visual Studio and it worked great. Then I ported it to Qt Creator (using Qt5, w/ MSVC 2015 Visual C++ toolchain) and I got runtime errors. It knows where to find the external header files, so I think my INCLUDEPATH is right, and it builds fine so I think the LIBS variables in my .pro file are right, which is to say it can find the .lib files it needs. However, the first API I call from this external library (viOpenDefaultRM) returns the following error: VI_ERROR_LIBRARY_NFOUND. This happens whether I make a debug build or a release build, and whether or not I am running it with a debugger. As long as I run the program from within Qt Creator, it gets runtime errors.
Here is my .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
LIBS += -L$$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc/' -lvisa64
INCLUDEPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
DEPENDPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
The paths that end with /Include have header (.h) files (it's a C library), and the path that ends with /msc has a .lib file. The .lib files are not static libraries, they are the interface files for some corresponding DLLs. Those DLL files are in C:\System32. There are also 32-bit versions in C:\SysWOW64. They may also exist elsewhere but if they do I am not aware of it.
Now, if I run it from cmd.exe it works fine. That is, if I open a cmd.exe terminal window and navigate to my Qt project's build directory (c:\blah\blah\blah\obj\debug\) and run the executable from cmd.exe, I get no runtime errors. It can connect to the external hardware, talk to it, all good things are happening, much rejoicing.
I've done a decent amount of searching and researching about this problem, and I am somewhat cursed by the fact that most people have the opposite problem, which means that problem (the opposite one of mine) is what turns up in Google/DuckDuckGo/StackOverflow/forum.qt.io/doc.qt.io searches. That problem usually has to do with missing/misplaced Qt libraries. Here is an example. The answer to this question usually ends up with a link to a page on how to deploy Qt projects for Windows, e.g. this article.
Also I've read this article from Qt on how to add libraries to your project, and it didn't help me out, but I could be missing something and/or doing it wrong.
This might be something really dumb I'm missing and frankly I hope it is. Thanks*10^6.
TL;DR: The kit I was using to compile in Qt Creator had a different PATH set than my system PATH. To fix this, I did echo %PATH in cmd.exe and copied all the stuff that had to do with the drivers I'm trying to use into the PATH for the kit I'm using in Qt Creator. More details below.
I got this to work this morning. As suggested by #adrien-lerevat, when run from within Qt Creator, my executable couldn't find some DLLs it needed. The long and short of it is that I was defining a PATH in my kit (a "kit" in Qt is basically a compiler, a debugger, and some environment variables) that was different from, and not a superset of, my normal system path. I had inherited this kit for other purposes, you see, from other projects, and I didn't realize a PATH could be set in it, or that I was setting one. So to find the PATH I was setting for Qt Creator, I went to the Tools dropdown and selected Options..., then Build & Run, then Kits. Then click on the kit you are using to edit it. As such:
That should give you a list of stuff, one thing of which is called Environment. That should have a Change... button you can press:
which should open a new window with all your environment stuff:
(screenshot is from after I fixed the problem)
This is where I found PATH, as well as some library and include paths that were worth knowing about. So now that I knew what my Qt Creator PATH was, I opened cmd.exe and typed the command echo %PATH% to find out what my system PATH was. I grabbed everything that had to do with these VISA drivers I'm using (basically anything with VISA and/or IVI Foundation in the path) and pasted them into my PATH in Qt Creator. This was the list of stuff I pasted in there to make it work:
C:\WINDOWS\system32;C:\Program Files\IVI Foundation\VISA\Win64\ktvisa;C:\Program Files\IVI Foundation\VISA\Win64\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\winnt\agvisa;C:\Program Files\Keysight\IO Libraries Suite\bin;C:\Program Files (x86)\Keysight\IO Libraries Suite\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa;C:\Program Files (x86)\IVI Foundation\IVI\bin;C:\Program Files\IVI Foundation\IVI\bin;
I added c:\system32 because I know that's where visa64.dll is, which is at least one top-level DLL I know I need. Oddly enough, though, when I added just c:\system32 without all the VISA and IVI Foundation stuff, that didn't work. So, I don't know if everything I added to my Qt Creator path was necessary, as I've just come upon this solution, but once I pare down the list to find out what all I actually needed I will add that information here. Just in case anyone else ever comes across this problem or is curious. And for the sake of completeness I suppose. Okay thanks everyone ;)
I would like to compile staticly my Qt 5 application. I used this link :
Qt static linking and deployment
The problem is that I don't know where is the "configure" file or how to generate it ?
ps: the old option to add "CONFIG = static" in the .pro file doesn't work with Qt5
You have to first compile the whole Qt library statically. Then, use that configuration in your projects. Then, your application will be statically compiled.
Qt (when using qmake) takes the compilation configuration from its qmakespec, which is defined during compilation of the Qt library. This includes all the parameters that are used by default.
Keep in mind that this has a learning curve. You have to try and fail a few times. It'll cost you some time to get this right. That link I provided should make this effort easier.
The problem is that I don't know where is the "configure" file or how to generate it ?
QMake make use of several type of files:
.pro
.pri
.prf
The most common is the .pro used for pro-jects. You can find/create it at the root of your project directory.
Creating a QtCreator project will automatically generate one. Be aware that there is also the qbs alternative.
the old option to add "CONFIG = static" in the .pro file doesn't work with Qt5
CONFIG *= static still works, are you sure about any other issue somewhere else?
CONFIG = static will override any previous value, using the * will append the new value without deleting previous configurations. I suggest you to use 'message( $$CONFIG)' to ensure the content is correct.
I am interested to import Itk-snap source code in Qt5.4. Based on their help I could built the executable itksnap in my system using cmake(3.4.1). Then, I have imported the Cmakelist.txt in Qt creator and pressed "run camke". It is configured successfully, but I cannot see the project file ( no main.cpp or any file in left panel)! , cannot build it because it does not loaded in Qt creator.
What do I do wrong? How can I have itksnap in my QT creator.
I am using OSX, and unix generator for camke.
As I can understand you are trying to build cmake project using QtCreator as an IDE, if so have a look here http://doc.qt.io/qtcreator/creator-project-cmake.html
Finally, I could find out what was wrong. For whoever is interested and have same problem like me, I recommend to do : first to build binary of itk-snap source file using Cmake-Gui and build based on their help to the different folder. After you are sure that you can make the binary file, goes to the Qt-Creator, change the Kit and other setting if its not correct, then open Cmakelist.txt from source of itk-snap. It shows a windows to run the cmake inside the QT-creator. Go back to your Cmake-Gui and from Tools >> show my changes menu, copy the argument and past to the argument textBox in QT. In my case variables are
-DVTK_REQUIRED_OBJCXX_FLAGS:STRING="" -DSNAP_USE_GPU:BOOL="1" -DVTK_DIR:PATH="/Users/../itkSnap3/vtk/build" -DITK_DIR:PATH="/Users/../itkSnap3/itk/build" -DCMAKE_PREFIX_PATH:PATH="/usr/local/Cellar/qt5/5.5.1_2/lib/cmake"
Good luck
So I have a simple app that uses QML for my graphical interface and c++ code for some of the logic. I was looking for a method to compile the QML into c++ code and link it into my binary and found this page over at the Qt home site:
http://doc.qt.io/QtQuickCompiler/
Basically it says use the resource system for all of my QML graphical interface files and add the QML compiler flag to my qmake config line in my .pro file and everything should be good to go.
As far as I know everything compiles fine, but when I use the the Qt windeployqt.exe tool to get all of the dependency files and test it on a clean system, I get a small white screen as if my QML files were not loaded properly.
I have one c++ reference to my main QML file using "qrc:/mainqml.qml" and that's it.
Any idea what I am doing wrong?
You're using the open source version of Qt. It didn't come with the Qt Quick compiler until Qt 5.11 where it is included - and after a rework, too. So it performs better than precompiled QML did in Qt 5.10 and before.
I get a small white screen as if my QML files were not loaded properly.
... thus you need to deploy these files with the application, otherwise it won't work.
add the QML compiler flag to my qmake config
That flag was a no-op on an open source Qt build until Qt 5.11.
Qt Quick Compiler only shipped with Qt Commercial License, but you can still compile your QML files into qrc file. Starting a Qt Quick application project from Qt Creator does exactly this.
Deploying QML application with windeployqt require additional flag --qmldir, e.g.
windeployqt --(release or debug) --qmldir %PATH_TO_YOUR_QML_FILES% %YOUR_APPLICATION%.exe
It will parse your qml files and deploy all qml imports you used.
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).