Qt 5 and LibVLC - c++

I'm working on a project which involves receive, display and rebroadcast several local network video streams. LibVLC seems to be the way to go, I'd like to use it within Qt Creator/C++/OSX 10.12.1 and I also need the project to be compilable on some Windows 10 machines where I have Qt installed.
I successfully tested some functionalities by installing the offical QT-LibVLC wrapper from projects.tano.si/vlc-qt. Unfortunately the wrapper lacks many LibVLC methods which are essential to my project, so I decided to install full LibVLC.
For now I'm stuck on how to make LibVLC work.
I followed all directions at https://wiki.videolan.org/OSXCompile/#Apple_Software
for installation and libraries building, and everything went fine.
Then I started a new project in QT, tried adding INCLUDEPATH += . vlc and LIBS +=-lvlc paths to the .pro file in Qt, but it does not work. Also adding paths to the "Framework" folder of the VLC build folder doesn't work.
Anyone knows how the magic trick?
Sorry, I know I'm a bit naive, but that's it...
Thank you in advance for any answer!
UPDATE:
thanks to eyllanesc suggestion this structure now works for the compiler:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testVLC
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
player.cpp \
main.cpp
HEADERS += \
player.h
macx: LIBS += -L$$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/lib/ -lvlc.5
INCLUDEPATH += $$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/include
DEPENDPATH += $$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/include
Unfortunately the application is launched but VLC instance is not initialized. Seems that my VLC installation has something wrong.
SOLVED:
After some tweaking the project compiles and starts correctly.
I don't understand why, but the environment variable VLC_PLUGIN_PATH has to be set just before instantiating VLC, otherwise VLC refuses to initialize:
//set environment variable VLC_PLUGIN_PATH
int s = setenv ("VLC_PLUGIN_PATH", "/Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/lib/vlc/plugins", 1);
// Initialize libVLC
vlcInstance = libvlc_new(0, NULL);
Actually it doesn't work at all if you set it in the Build Environment of QtCreator.

A simple way to include libraries for our application is with the help of Qt Creator, this one has an assistant, to be able to use it just right click on the name of your project:
Then select the Add Library option.
Then the assistant opened:
And select the type of import, in your case it is advisable to use External Library.
Then you look for the location of your project and you accept.
Note: In Linux this tool can be opened with the shortcut Ctrl + E

Related

Tesseract in QT

This is the first time I am asking a question here.
I want to use Tesseract API in QT.
My idea was to design a programme using QT that would read aloud messages (QSpeech) from Telegram Desktop version (not that important).
Tesseract came across as a tool I needed so I tried to implement it. I wanted to use its API, but finally I ended up using QProcess to call Tesseract as a programme.
HERE'S THE PROBLEM.
After including tesseract and leptonica libraries to .pro file i get this:
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag'
How to fix it?
I use QT 5_12_3
I included the libs.
INCLUDEPATH += "/usr/include"
LIBS += -L"/usr/local/lib" -ltesseract
INCLUDEPATH += "/usr/include"
LIBS += -L"/usr/lib/x86_64-linux-gnu" -llept
I downloaded QT from the official website. Tesseract API code is an example taken from the documentation. From the same documentation I followed instructions to download everything needed. As I mentioned before, if I compile a text file with the code sample, then it works fine. I just can't integrate it into QT.
Tesseract and Leptonica create pkg-config files, so you didn't have to manually add INCLUDEPATH or LIBS to your project, instead use
QT_CONFIG -= no-pkg-config
Config *= link_pkgconfig
PKGCONFIG *= tesseract
If it doesn't work for you, check whether the Tesseract is installed correctly (also check that you have tesseract.pc file in your system).

z.lib problems while porting qt creator projet to windows

I am trying to port a Qt5.9 project from Mac to Windows 10.
I was able to compile the project easily in a ubuntu installation.
While trying to build it for windows, i had problems with finding zlib include headers with
#include<zlib.h>
That i corrected after following answers here on Stack to
#include<QtZlib/zlib.h>
Now i have problems in LINK phase, it can not open the file z.lib
Problem is i downloaded zlib packages, builds, source code and could not find a z.lib. Only different named libs. Searching in google i could only find people with the same problem, z.lib is not one of the libs included in zlib installation.
This is my project file:
TEMPLATE = app
QT += qml quick widgets websockets
CONFIG += c++11
SOURCES += \
main.cpp \
api.cpp \
app.cpp
HEADERS += \
api.hpp \
app.hpp
RESOURCES += qml.qrc
LIBS += -lz
I tried putting all possible dll and lib files in the project folder. None of them is named z.lib though.
The symbols for zlib are already part of the qt libraries. As long as you do not try to link the zlib explicitly it should work. At least it does work for me.
add to your project file:
!win32 {
LIBS += -lz
}
I managed to solve my problem updating my Qt installation to use MinGw 5.3 32bit. I was using VisualStudio 2015 as the compiler before.
Only changing the compiler to MinGw (g++) 5.3 made everything work with the same pro file i posted in the original question. Thanks everybody who tried to help!

How to create Qt executable for linux machines

I have created a project using Qt 5.3. I want this project to be executable on other linux machines, so I took the executable file which is generated in the build folder of the project and executed it on the other linux machine. When I did that I got the following error:
./Project_name: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory
I developed the application using QT 5.3 but the linux machine where I am trying to execute it has libqt4 libraries. Is there any way for this file to be executable using the libqt4 libraries only.The following is my .pro file of the project:
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-08T09:19:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Project_name
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp\
mainwindow.cpp \
INCLUDEPATH += /usr/include/python2.7/
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I checked online and found out that we need to make changes in the "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets" so that it works for qt4 libraries. I did that but it did not work. So could you let me know what could be done so that the project which is built using libqt5 can also be executed on machines which have libqt4. Installing libqt5 libraries can be done but I am looking for a way other than that.
Is there any way for this file to be executable using the libqt4 libraries only
Not easily at least... Even if you created symlinks, Qt 4 and Qt 5 are not binary compatible.
If you want to make it self-contained:
bundle the libraries statically.
Use dynamic symbol loading and based on the version you find, you may need to program the code to act differently. But it may be a hell lot of work.
hey make sure libqt5widgets are installed on your system and you are using the correct qmake (version 5x in your case) you can installl them on debian based distro by issuing the command or via Synaptic package manager
sudo apt-get install libqt5widgets5

Installing libusb on windows for use with Qt

I'm trying to install libusb (not libusb-win32) on windows 7. I have to link it with Qt 5.0.1. Here are the problems I'm facing
In the INSTALL file in the extracted libusb folder, it tells me to cd to the current folder then run
./configure
make
makeinstall
But I got the error
'./configure' is not recognized as a valid command.
Googling this problem usually gives the solution as installing libusb-win32. However, I want to avoid that, as of now.
In the libusb library, there were a few MSVC projects, so I built them. That did generated some .lib files. So I proceeded to link them with my Qt project. It recognizes the libusb.h header file but does not link properly. Here is my .pro file
QT += core gui widgets
TARGET = Qt_libusb TEMPLATE = app
SOURCES += main.cpp\
qt_libusb.cpp
HEADERS += qt_libusb.h
FORMS += qt_libusb.ui
LIBS += -LC:\libusb-1.0.18\Win32\Debug\lib\libusb-1.0
INCLUDEPATH += C:/libusb-1.0.18/libusb DEPENDPATH += C:/libusb-1.0.18/libusb
My objective is to link the libusb library with Qt. Please tell me if I haven't 'installed' the library correctly or if I am linking it in a wrong way. thanks
Your project file does not reference the library. You only provide a path where libraries might be found, but there's no reference to the libusb library itself.
What you're missing is something like
LIBS += -llibusb
You also can't have multiple project file statements on the same line. The below is an error:
TARGET = Qt_libusb TEMPLATE = app
It should look like:
TARGET = Qt_libusb
TEMPLATE = app

Using SFML with Qt creator?

I've recently began learning the SFML API for learning purposes but it seems to me like it only supports Codeblocks IDE and Visual Studio. I dislike both IDEs for my own ideas and I like the IDE that comes with Qt instead.
Is it possible to basically use SFML within the Qt creator?
EDIT:
I know some of you may some day find this on google, after struggling for 8 days to set up sfml to work with qt creator I've found the sollution:
step 1: Download the VS version of SFML from the website (NOT codeblocks version)
step 2: copy the DLLs from C:\SFML-1.6\lib to your system32 directory
step 3: open qt creator, make a plain C++ project, open your .pro file and add these lines:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
And you're done!
Short answer: Yes.
The IDE doesn't really matter all that much. The compiler does. Depending on the compiler used by Qt Creator, you download the appropriate SFML package. Most likely the MinGW based version will work just fine with your default install of Qt Creator. (I believe that relies on MinGW?)
All that then remains to be done is place SFML in its own directory and making sure that you set up the correct paths in your Qt Creator project. There's not much to it really.
I know i'm a little bit late to the party but:
SFML library is 100% compatible with qtcreator especially qmake.
Download SFML from https://www.sfml-dev.org/download/sfml/2.5.1/ . Bottom right minGW (You most likely have mingw on qt)
Place it somewhere you will know where it is. I usually put it in "C:/SFML-2.5.1"
There's a simple copy pasta you can add to your qmake '.pro' file:
INCLUDEPATH += "C:/SFML-2.5.1/include"
LIBS += -L"C:/SFML-2.5.1/lib"
CONFIG(debug, debug|release){
LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-system-d -lsfml-window-d
} else {
LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window
}
The 'INCLUDEPATH' includes the headers into your project where as the 'LIBS' adds the library file path. The 'CONFIG()' tells qt if you're running DEBUG mode or RELEASE mode.
This copy pasta is fun because you can also configure a custom wizard and make qt dropdown show you a 'create new sfml c++' project by just editing its profile with this.
Last but not least are the needed .dll files from 'C:\SFML-2.5.1\bin' You can add only the ones you need or all of them if you're lazy. You can do this by copying them into the BUILD folder of your project. (to find the build folder by default its a folder in the same path as your project folder with the name of your project prefixed by 'build-' or 'release-')
Make simple c++ project
Choose QMake build system
in project.pro add 2 lines:
CONFIG += link_pkgconfig
PKGCONFIG += sfml-all