I want to develop a media player using Qt. On the basis of the documentation I have done the following things:
pro file
QT += core gui multimedia
QT += multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Player
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
main.cpp file
#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer *player=new QMediaPlayer;
QVideoWidget *videowidget=new QVideoWidget;
QMediaPlaylist *playlist=new QMediaPlaylist;
playlist->addMedia(QUrl("C:/Users/Administrator/Desktop/VideoLAN/VLC/stram.mp4"));
player->setVideoOutput(videowidget);
playlist->setCurrentIndex(1);
player->setPlaylist(playlist);
player->play();
videowidget->show();
return a.exec();
}
As for the header file I have included mainwindow.h
EDIT
All the erorrs are gone but now the output which is coming is:
Where am I going wrong?
Try add this string to .pro file:
QT += multimediawidgets
for additional info: http://qt-project.org/doc/qt-5/qvideowidget.html
Related
I develop a generic interface library with qt. I have trouble with pressed effect on QPushbutton when I click with a touch screen (this effect appears one time on 10 click).
So I create a basic qml application with one button and pressed effect appear all time. I incude the qml part into my library and load it in QQuickWidget and I have same problem with pressed effect.
So I want to use only qml. My principal application is a QApplication and I load my library in it in which I load qml file with QQmlApplication Engine. Then I show it by QQuickWindow.
When I launch my application I saw the window open but it is automatically close. I think my QApplication don't detect QML and the renderer loop is not start.
I'm on windows with QT5.5.1 (MSVC2013, 32bit)
pro file of main application
QT += core xml widgets qml quick
TARGET = COM_INT
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
comint.cpp
HEADERS += \
comint.h \
INCLUDEPATH += "$$(My_Workspace)/Modules_Generique/IHM_Soft"
Release{
LIBS += "$$(My_Workspace_build)/IHM_Soft/release/IHM_Soft.lib"
}
Debug{
LIBS += "$$(My_Workspace_build)/IHM_Soft/debug/IHM_Soft.lib"
}
Main application (exe) main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include "comint.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ComInt com;
com.initialize();
return a.exec();
}
ComInt class:
Source file comint.cpp
#include "comint.h"
#include "ihmsoft.h"
ComInt::ComInt()
{
}
void ComInt::initialize()
{
this->m_pIHMSoft = new IHMSoft();
}
header file comint.h
#ifndef COMINT_H
#define COMINT_H
class IHMSoft;
class ComInt
{
public:
ComInt();
void initialize();
private:
IHMSoft *m_pIHMSoft;
};
#endif // COMINT_H
pro file of shared lib
QT += xml widgets core qml quick quickwidgets
CONFIG += c++11
TARGET = IHM_Soft
TEMPLATE = lib
DEFINES += IHM_SOFT_LIBRARY
SOURCES += ihmsoft.cpp
HEADERS += ihmsoft.h\
ihm_soft_global.h
RESOURCES += \
rsc.qrc
Shared library: source file ihm_soft.cpp
#include "ihmsoft.h"
#include <QQmlApplicationEngine>
#include <QQuickWindow>
IHMSoft::IHMSoft(){
qputenv("QT_QUICK_CONTROLS_STYLE", "Base");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/IHM_Soft.qml")));
QList<QObject*> root = engine.rootObjects();
QQuickWindow *window = qobject_cast<QQuickWindow*>(root.at(0));
window->show();
}
header file ihm_soft.h
#ifndef IHM_SOFT_H
#define IHM_SOFT_H
#include "ihm_soft_global.h"
class IHM_SOFT_SHARED_EXPORT IHM_Soft
{
public:
IHM_Soft();
};
#endif // IHM_SOFT_H
Global file ihm_soft_global.h
#ifndef IHM_SOFT_GLOBAL_H
#define IHM_SOFT_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(IHM_SOFT_LIBRARY)
# define IHM_SOFT_SHARED_EXPORT Q_DECL_EXPORT
#else
# define IHM_SOFT_SHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // IHM_SOFT_GLOBAL_H
Qml file
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
visible: true
width: 500
height: 500
Button {
visible: true
iconSource: "resources/t_on_off.png"
}
}
Edit: Sorry the code of the main application was a test application which do not include lib.
A variable is deleted when its scope ends, in your case engine is a local variable that is deleted when IHMSoft finishes being built, so you see that the window closes. The solution is to make it a member of the class:
*.h
#ifndef IHM_SOFT_H
#define IHM_SOFT_H
#include "ihm_soft_global.h"
#include <QQmlApplicationEngine>
class IHM_SOFT_SHARED_EXPORT IHM_Soft
{
public:
IHM_Soft();
private:
QQmlApplicationEngine engine; // member
};
#endif // IHM_SOFT_H
*.cpp
#include "ihmsoft.h"
IHMSoft::IHMSoft(){
qputenv("QT_QUICK_CONTROLS_STYLE", "Base");
engine.load(QUrl(QStringLiteral("qrc:/IHM_Soft.qml")));
}
I'm trying to use the qdarkstyle theme.
Ive followed the code but I cant seem to load the stylesheet. Here is how i'm loading the code in main.cpp:
QFile f(":qdarkstyle/style.qss");
if (!f.exists())
{
printf("Unable to set stylesheet, file not found\n");
}
else
{
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
qApp->setStyleSheet(ts.readAll());
}
but exists() is always false. The folder qdarkstyle is in the sub-directory of my main source
My project Resources looks like this:
Ive tried the following calls:
QFile f(":qdarkstyle/style.qss");
QFile f("://qdarkstyle/style.qss");
QFile f(":/qdarkstyle/style/qdarkstyle/style.qss");
but I always exists is always false. Any ideas on what i'm doing wrong
Adding My .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MediaManagerV2
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc \
qdarkstyle/style.qrc
Link to source
https://drive.google.com/file/d/0BwXCsqWT3wkXV1dYNzF1dFM4dTQ/view?usp=sharing
Fix
Modified code
QApplication a(argc, argv);
MainWindow w;
w.show();
QFile f(":/qdarkstyle/style.qss");
if (!f.exists())
{
printf("Unable to set stylesheet, file not found\n");
}
else
{
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
a.setStyleSheet(ts.readAll());
}
basically moved show() above
You have added the .qrc file to your .pro:
RESOURCES += qdarkstyle/style.qrc
And move show() before calling the stylesheet.
This Question has been asked by different people about 3times by QLands: here and carnifrex: here and there. My problem is exactly like carnifrex's: I am trying to compile my application to connect to MYSQL(Mariadb) database without Mariadb installation i.e embedded server but I get this Error Below:
error: undefined reference to 'imp__ZN12QMYSQLDriverC1EP8st_mysqlP7QObject' collect2.exe:-1: error: error: ld returned 1 exit status
Unfortunately, carnifrex was not replied. Here's my Code
main.cpp:
#include "mainwindow.h"
#include <QApplication>
#include <QSql>
#include <QMessageBox>
#include "qsql_mysql.h"
#include <mysql.h>
bool createConnection(QMYSQLDriver *drver)
{
QSqlDatabase db = QSqlDatabase::addDatabase(drver);
db.setHostName("localhost");
db.setDatabaseName("exama");
db.setPort(3306);
db.setUserName("root");
db.setPassword("Adm1n16");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MYSQL *mysql;
static char *server_options[] = \
{"mysql_test", "--defaults-file = C:/Program Files (x86)/MariaDB 10.1/data/my.cnf", NULL };
int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
static char *server_groups[] = { "embedded", NULL };
qDebug() << "Loading embedded";
mysql_library_init(num_elements, server_options, server_groups);
mysql = mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "embedded");
mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
mysql_real_connect(mysql, NULL,NULL,NULL, "database1", 0,NULL,0);
QMYSQLDriver *drv = new QMYSQLDriver(mysql);
if (!createConnection(drv))
return 1;
MainWindow w;
w.show();
return a.exec();
}
mysqlConnect.pro:
QT+=core gui sql\
widgets \
greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
INCLUDEPATH += "C:\Qt\Qt5.4\5.4\mingw491_32\include\QtSql\5.4.0\QtSql\private"
INCLUDEPATH += "C:\Program Files (x86)\MariaDB 10.1\include\mysql"
QMAKE_LIBDIR += "C:\Program Files (x86)\MariaDB 10.1\lib"
LIBS += -lmysql
TARGET = mySQLConnect
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
QMAKE_CXXFLAGS+=-std=c++11
The compilation fails at this line in main.cpp:
QMYSQLDriver *drv = new QMYSQLDriver(mysql);
I am using Qt Creator 5.4.0 with MingW 4.9.1 32bit on x64 bit Windows 7 Machine. I will be grateful for any assistance granted.
I'm trying to run (in Qt, C++) the following code that uses OpenCV:
.pro file:
QT += core
QT -= gui
TARGET = testOpenCV2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv\release\bin\libopencv_core300.dll
LIBS += C:\opencv\release\bin\libopencv_highgui300.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs300.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc300.dll
main.cpp file:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
cv::Mat image = cv::imread("pic.jpg", CV_LOAD_IMAGE_COLOR);
cv::namedWindow("My Image", WINDOW_AUTOSIZE);
cv::imshow("My Image", image);
cv::waitKey(0);
return 0;
}
But I'm getting the following message:
exited with code -1073741515
And sometimes I get the following message:
Cannot obtain a handle to the inferior: The parameter is incorrect.
and nothing is happening.
Can anyone help me please?
I'm new in Qt and I don't know what's going on.
You are not using Qt at all (except you try link QtCore). For running a QtApplication you would at least need to call QCoreApplication.
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Some code here
// QMainWindow w;
// w.show();
return a.exec();
}
Creating a non Qt application you would change your pro-file to (omit the QT at all):
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv\release\bin\libopencv_core300.dll
LIBS += C:\opencv\release\bin\libopencv_highgui300.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs300.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc300.dll
This way you also won't need ''QCoreApplication''
I tried to use libjpeg-turbo with qt.
I downloaded libjpeg-turbo and installed. I wanted to use it within a project but I got the following fault:
C:\libjpeg-turbo-gcc64\bin\libjpeg-62.dll:-1: Error: file not
recognized: File format not recognized
As soon as I removed the libjpeg-62.dll I received the following fault:
C:\test\main.cpp:8: Error: undefined reference to
`tjInitCompress'
Why is the libjpeg-62 not recognizing the file format?
Thanks for help,
Willy
PS. Here is the code:
test.pro
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\libjpeg-turbo-gcc64\include
LIBS += -LC:\libjpeg-turbo-gcc64\bin -llibjpeg-62
main.cpp
#include <QCoreApplication>
#include <turbojpeg.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
tjhandle _jpegCompressor = tjInitCompress();
return a.exec();
}
Ok now it works,
it was the wrong version of libjpeg-turbo. Now I use the libjpeg-turbo-gcc and not the libjpeg-turbo-gcc64. Also i change the Libs-Path to
LIBS += "C://libjpeg-turbo-gcc64//bin//libjpeg-62.dll"
MfG Willy