Qt embedding MYSQL - c++

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.

Related

C++ QT libXL Error: "During Startup program exited with code 0xc0000135"

I am trying to write a QT application that uses libXL, but when I try to compile, I get a pop up box saying "During Startup program exited with code 0xc0000135". I have figured out exactly which line causes the problem, it is the "Book* book = xlCreateBook();" line in startgame.cpp. When I comment this line out, the program runs fine. Is it possible that I set up the library incorrectly? I will try to include all relevant code below, and thanks in advance for any help!
stattracker.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Stattracker
TEMPLATE = app
SOURCES += main.cpp\
stattracker.cpp \
startgame.cpp
HEADERS += stattracker.h \
varstruct.h \
startgame.h
FORMS += stattracker.ui
win32: LIBS += -L$$PWD/libxl-3.6.4.0/lib/libxl.lib
INCLUDEPATH += $$PWD/libxl-3.6.4.0/include_cpp
main.cpp
#include "stattracker.h"
#include <QApplication>
#include "varstruct.h"
#include <QString>
#include <windows.h>
#include <shlobj.h>
gameManager gm;
wchar_t homePath[MAX_PATH];
wchar_t awayPath[MAX_PATH];
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
gm = *new gameManager;
homePath[MAX_PATH] = *new wchar_t;
awayPath[MAX_PATH] = *new wchar_t;
Stattracker w;
w.show();
return a.exec();
}
startgame.cpp
#include ...
void Stattracker::initializeVars()
{
//This function initializes all game variables to starting value
}
void Stattracker::newFile(QString path, QString firstName, QString lastName)
{
using namespace libxl;
Book* book = xlCreateBook(); //WHEN THIS LINE IS COMMENTED, THE PROGRAM COMPILES FINE
}
void Stattracker::getInput()
{
bool homePosition[11], homeOrder[10], awayPosition[11], awayOrder[10];
wchar_t my_documents[MAX_PATH];
gm.homeTeam.teamName = ui->teamName->text();
gm.awayTeam.teamName = ui->teamName_2->text();
HRESULT result = SHGetFolderPath(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,my_documents);
QString documentsPath = QString::fromWCharArray(my_documents);
QString homePathA = documentsPath + "\\Stattracker\\" + gm.homeTeam.teamName;
QString awayPathA = documentsPath + "\\Stattracker\\" + gm.awayTeam.teamName;
QString pathCheckA = documentsPath + "\\Stattracker\\";
QString curFileA;
wchar_t pathCheckB[MAX_PATH];
wchar_t curFile[MAX_PATH];
pathCheckA.toWCharArray(pathCheckB);
homePathA.toWCharArray(homePath);
awayPathA.toWCharArray(awayPath);
if((GetFileAttributes(pathCheckB))==INVALID_FILE_ATTRIBUTES)
{
CreateDirectory(pathCheckB, 0);
}
if((GetFileAttributes(homePath))==INVALID_FILE_ATTRIBUTES)
{
CreateDirectory(homePath, 0);
}
if((GetFileAttributes(awayPath))==INVALID_FILE_ATTRIBUTES)
{
CreateDirectory(awayPath, 0);
}
if(ui->firstName->text()!="First Name" && ui->lastName->text()!="Last Name")
{
gm.homeTeam.roster[0].firstName = ui->firstName->text();
gm.homeTeam.roster[0].lastName = ui->lastName->text();
curFileA = homePathA + "\\" + gm.homeTeam.roster[0].lastName + "_" + gm.homeTeam.roster[0].firstName + ".xls";
curFileA.toWCharArray(curFile);
if((GetFileAttributes(curFile))==INVALID_FILE_ATTRIBUTES)
{
}
}
}
void Stattracker::startGame()
{
initializeVars();
getInput();
}
Let me know if I should include any of the other files (stattracker.cpp, stattracker.h, or varstruct.h)
Find libxl.dll and place it in the same directory as you .exe

OpenCV and Qt 5.3 weird message

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''

libjpegTurbo: libjpeg-62 File not recognized

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

C++: Media Player using Qt

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

Qt c++ embedded mysql

I've been writing a program on QT 5.0.2 with mingw 4.7 on windows with mysql server 5.7.
I first started with installing the MYQSL driver for QT with this tutorial. It works and I can access the data, but i have to start the server from mysql workbench or it won't make a connection with the database (because it's not running).
For my program I need the server to start up when I run the program. This is the part where i'm stuck. I know I need to use the libmysqld library but I don't seem to get it to work. I didn't find much useful examples so i tried it like this:
this is the .pro file:
QT += core sql
QT += sql
QT -= gui
TARGET = Temp
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:\Program Files (x86)\MySQL\MySQL Server 5.7\include"
INCLUDEPATH += "C:\Program Files (x86)\MySQL\MySQL Server 5.7\lib"
LIBS += -L"C:\Program Files (x86)\MySQL\MySQL Server 5.7\lib" -llibmysqld
this is my main file:
#include <QtSQL>
#include <qsql_mysql.h>
#include <mysql.h>
int main(int argc, char *argv[])
{
QSqlDatabase mydb;
MYSQL *mysql;
static char *server_options[] = \
{ "mysql_test", "--defaults-file=/home/cquiros/temp/mysql/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);
mydb = QSqlDatabase::addDatabase(drv,"connection1"); //Add the database connector to MySQL
mydb.setDatabaseName("test");
if (!mydb.open()) //Try to opens the database
{
qDebug() << "Error while opening the database";
}
}
When i run this, i get this error: "
error: undefined reference to `imp__ZN12QMYSQLDriverC1EP8st_mysqlP7QObject'
collect2.exe:-1: error: error: ld returned 1 exit status
Can anyone help me get on track?