Using Phonon in Qt5 - a simple video player - c++

So what I'm trying to do is stream an ip camera using phonon (vlc backend) in qt5.
I know phonon needs some changes in order to work in qt5 and I've made them, the libraries which used weren't writable, I made them writable, edited them but I'm still getting lots of errors.
Then I assumed there might be something wrong with phonon! so I downloaded phonon for qt 5. but the result was the same.
even creating an object gives me errors, after Googling my error, I found out there is linking problem but I don't know how to fix it.
.pro file:
Qt += phonon4qt5
header file:
#include <phonon4qt5/phonon/VideoPlayer>
.
.
.
Phonon::VideoPlayer *videoPlayer;
cpp file:
videoPlayer=new Phonon::VideoPlayer(Phonon::VideoCategory,this);
I get these errors:
/home/user/Projects/VideoPlayer-Phonon2/mainwindow.cpp:9: error: undefined reference to `Phonon::VideoPlayer::VideoPlayer(Phonon::Category, QWidget*)'
:-1: error: collect2: error: ld returned 1 exit status

Why are you struggling with Phonon? It's no longer supported in Qt5!
Anyway, undefined references means that you need to link the library explicitly. You have included with Qt += phonon4qt5, now you have to provide LIBS += -L/path/to/phonon -lphonon4qt5

Related

Using grpc with QtCreator, undefined reference to `grpc::...`

I am trying to write some code in C++ in QtCreator to connect to a grpc server when I get this compiler error:
/some/path/serverproxy.cpp:40: error: undefined reference to `grpc::InsecureChannelCredentials()'
Here's my grpc includes at the top of serverproxy.cpp
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
#include <grpc++/security/credentials.h>
and the error comes from this line:
somenamespace::NewStub(
grpc::CreateChannel("someaddress",
grpc::InsecureChannelCredentials()))};
I tried adding existing files and adding these headers in QtCreator (although it would be very strange to have to do that manually for the headers to all external libraries), but it didn't work. They are located at /usr/local/include/grpc++/**/*.h.
Also tried adding INCLUDEPATH += /usr/local/include to my .pro file.
I also tried cleaning the project, running qmake and building again.
What do I have to do to be able to use these grpc++ functions?
I looked at so many undefined reference in qtcreator threads without noticing this, which I finally saw here which is what got rid of the undefined reference errors:
You are facing a link error. Just add in your .pro the path to your
lib and its name with :
LIBS += -L<path_to_the_lib> -l<libName>
specifically
LIBS += -L/usr/local/include/grpc++ -lgrpc++

vtk autoinit linker error

I have a very confusing (at least for me :) ) problem with linking to vtk-libraries. On one desktop pc, my code compiles without any error. I have an identical installation on another pc, but there, I get linker errors.
On both pc's are installed: itk 4.8, vtk 6.3 and cmake 3.3. Both are debian-systems (8.1 - jessie).
[ 96%] Linking CXX executable project
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit::~vtkRenderingVolume_AutoInit()':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit::~vtkRenderingVolumeOpenGL_ModuleInit()':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
libcommon.a(datareader.cpp.o): In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:326: recipe for target 'project' failed
I tried to fix those errors with adding
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
to the file where I am using the vtk libraries, but it didn't help.
Does anyone know what I'm doing wrong? I am wondering, why it works on one of those pcs but not on the other one.
thank you very much!
Update: I fixed my problem by switching the position of
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
in the CMakeLists to the end. However, does anyone know, why it makes such a huge difference for different pcs?
As long as the VTK_USE_FILE is found, your code should compile correctly. In your other PC, VTK_USE_FILE was already found from a previous configuration and sits in a CMake cache entry, so that is why it compiles fine.
If your are using Nightly,
Your should put these in front of your including any vtk headers.
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
and link all the library you made from vtk source

QtAddon SerialPort from Qt4 to Qt5

I am migrating a project from Qt4 to Qt5. I finished migrating the project itself and now I am working on the libraries. So far I haven't had many problems converting and linking them to the project, but this one is throwing undefined references.
The project uses QtSerialPort, and it compiled perfectly using the Qt4 version of it, and it was linked like this in the .pro file:
-l:"C:/Users/Sprint/Desktop/swe/marssies/libQtSerialPort.a" \
I have compiled the Serial Port library with/for Qt5 and linked it as follows:
-l:"C:/Users/Sprint/Desktop/swe/marssies/libQt5SerialPort.a" \
But I keep getting these errors:
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4ecc): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::availablePorts()'
Makefile.Release:922: recipe for target '..\Release\Swibz.exe' failed
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f3e): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::portName() const'
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f5d): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::description() const'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: ./release\gpssettingswidget.o: bad reloc address 0xd in section `.text$_ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget[__ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget]'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [..\Release\Swibz.exe] Error 1
I know its a linker error because of the "ld returned 1 exit status"
I have tried linking the libQt5SerialPortd.a, libQt5SerialPort.dll and libQt5SerialPortd.dll but it throws the same errors
(By the way, if someone knows the difference between libNAMEd.a and libNAME.a please share your knowledge)
Maybe the QtAddOn is now in another library? Because otherwise it shouldnt recognize many other functions, not only the ones with QtAddOn.
Thankyou very much. I don't know what I would do without stackoverflow.
EDIT Alright, I found this which tells to change any SerialPortInfo declared variable to QSerialPortInfo, I have done that in my project and I am getting new errors, but now I am not sure which #include I should put:
#include <QtSerialPort>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QtSerialPort/QtSerialPort>
I have tried each one of these and all give me errors. Ill keep trying and see if anything comes clear
QtSerialPort is now a part of Qt. It officially became part of Qt with the 5.1.0 release. If you use the new version of Qt there is no need to get the source code separately and link to it.
To use the module with Qt 5 add this line to your qmake project file:
QT += serialport
You can then include the header files. To use these classes in your application, use the following include statement:
#include <QtSerialPort/QtSerialPort>
There is quite good documentation for the classes. You can view it from Qt Assistant.

Compiler Command Line in Qt (Boost Related)

I have a problem when using <boost/thread.hpp> in my code. When I try to compile it in Qt, I get these errors:
undefined reference to boost::system::generic_category()
undefined reference to boost::system::generic_category()
undefined reference to boost::system::system_category()
error: ld returned 1 exit status
Anyway, I searched StackOverflow and found this:
Undifined Reference With Boost When I Try To Compile
They say the key to solve this problem is adding -lboost_system. But where should I add this?? :( I'm a newbie in boost and Qt and I want don't wanna compile my programs using command-line directly. Is there a way to add these command-line options to Qt Creator?
I use Qt 5 with MinGW compiler and Boost 1.53. Thanks.
Add it to your .pro file:
LIBS += -L<their location> -lboost_system
I'm assuming that you have the boost_system library installed in a place the compiler will look of course.

Trouble using Botan with Qt

I am using Qt and I am trying to use Botan. Everything seemed to go well, but when I go:
Botan::BigInt myInt;
In my constructor it works fine, but on the other hand if I go:
Botan::AutoSeeded_RNG rng;
It throws undefined errors:
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\mainwindow.o:-1: In function `AutoSeeded_RNG':
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\..\..\..\botan\include\botan\auto_rng.h:40: error: undefined reference to `_imp___ZN5Botan23Global_State_Management12global_stateEv'
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\..\..\..\botan\include\botan\auto_rng.h:40: error: undefined reference to `_imp___ZN5Botan13Library_State10global_rngEv'
:-1: error: collect2: ld returned 1 exit status
I have no idea why it would work with a BigInt but not the AutoSeeded_RNG, but here are my exact steps:
Compiled the Botan source included in the Qt Creator source at "src/libs/3rdparty/botan/"
I installed Botan using the Windows Installer (1.10) from their website.
I took the libBotan.a, libBotand.a, botan.dll, and Botand.dll and put them in the location where I installed Botan (C:\botan). I overwrote any of those files that already existed.
I then created a new Qt project, and inside of the .pro file I added the following lines:
INCLUDEPATH += "C:/botan/include"
LIBS += "C:/botan/libBotan.a"
Next, I go into my "mainwindow.cpp", and add:
#include <botan/botan.h>
Everything compiles up to here successfully.
I now add this to my constructor:
Botan::AutoSeeded_RNG rng;
Now the above errors are thrown, and cannot be ran. If I replace the "AutoSeeded_RNG" with "BigInt", then it compiles perfectly.
Thanks for any help, Hetelek.
The statement to link against the Botan library looks strange to me. Normally, you specify library directories using the -L switch and add a library with the -l switch, i.e you should use
LIBS += -L"C:\botan" -lBotan
Note that the prefix and suffix of the library are not specified in lbotan. The linker will automatically look for a libbotan.a or botan.dll, depending on your environment.
Botan is also part of QtCreator. Maybe you should have a look at their repository. You can find .pri and .pro files there and probably only need to copy them. They also have written a .qbs driver for the new Qt build system.
Edit: I just compiled Botan from the QtCreator sources, as you also mentioned in your post. I then copied all the generated libraries in my own directory and I also used the botan.h which was shipped with QtCreator. On Linux I had to add
LIBS += -L"/dir/into/which/i/copied/botan/dlls" -LBotan -ldl
to the qmake .pro file. Note the additional -ldl otherwise I got undefined references to dlym, dlerror etc. I could compile a simple example with Botan::AutoSeeded_RNG without problems.