std::ANYTHING is not declared - c++

I ended up formatting the computer to ubuntu 16.04
Solutions I've tried based on the answers:
Just deleted 'using namespace std;' line and didn't work.
I put that line before and after '#include ', neither
worked.
Thanks Yksisarvinen
Deleted all files other than QT's defaults app (and the images, of course)
tried this, but got the same error
//#include "mainwindow.h"
//#include <QApplication>
#include <QtCore>
int main() { qDebug() << "Hello, world!"; }
/*
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
*/
Thanks Kuba Ober
Added the following line to the .pro file. This solution worked for compiling using QT
INCLUDEPATH +=/usr/include
but I still can't compile using the terminal (this is a part of my history)
cat main.cpp
g++ main.cpp
echo $LD_LIBRARY_PATH
g++ main.cpp
LD_LIBRARY_PATH='' g++ main.cpp
export LD_LIBRARY_PATH=''
echo $LD_LIBRARY_PATH
g++ main.cpp
ls /usr/include/c++/7/
echo $CXX
echo $CC
echo $CC=clang
export CC=clang
export CXX=clang++
echo $CC=clang
echo $CC
g++ main.cpp
echo $INCLUDEPATH
export INCLUDEPATH = /usr/include
export INCLUDEPATH=/usr/include
echo $INCLUDEPATH
ls
g++ main.cpp
echo $INCLUDEPATH
history
I can work now (and probably I'll format ubuntu on vacations), but I don't want to mark this as solved since there is still something not working propperly.
Thanks Marcelo Cardenas (a friend from university)
Thanks for the tips anyway, hope we can solve this
I have this QT app:
https://drive.google.com/file/d/15d4mYLgJcKOB5tpEwfuFBPXETUbR8CFK/view?usp=sharing
Which used to work. Now I'm getting
this.
500+ errors of supposedly supposedly undefined functions.
I don't know where to even look for the error.
I'm currently working with:
OS: Ubuntu 18.04.1 LTS
Kernel: 4.16.0-041600-generic
Cuda: Built on Tue_Jun_12_23:07:04_CDT_2018 Cuda compilation tools,
release 9.2, V9.2.148
gcc: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
QMake: version 3.1
Qt version: 5.9.6
OpenGL version: 3.0 Mesa 18.0.5
OpenCV version: 4.0.0 (obtained by the command cat
/home/pablo/OpenCV-3.0.0/OpenCV-3.0.0-master/opencv/build/OpenCVConfig.cmake
)
Here is the .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2018-10-31T18:03:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Ayudantia2
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
And the header
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <ui_mainwindow.h>
#include <set>
//#include <mainwindow.h>
#include <QMainWindow>
#include <QFileDialog> //para buscar archivos por ventana
#include <QMessageBox> //para mensajes del sistema
#include <QImage> //para manipular imagenes basicamente(mas fome que opencv)
#include <cstdlib>
using namespace std;
#include <iostream>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void cargarTexto(QString);
void cargarImagen(int area);
void buscarImagen1();
void buscarImagen2();
void buscarImagen3();
void mostrarImagen4();
void mostrarImagen5();
void mostrarImagen6();
void filtrarImagen();
void ponderar();
void colorPlano();
signals:
void textoListo(QString);
int imagenLista(int);
int filtrar1(int);
int filtrar2(int);
int filtrar3(int);
int valueChanged();
void cambiocolor();
QString ruta1(QString);
QString ruta2(QString);
QString ruta3(QString);
private slots:
private:
Ui::MainWindow *ui;
QImage imagenes[8];
};
#endif // MAINWINDOW_H
and this id the mainWindow
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget* parent):
QMainWindow(parent),
ui(new Ui::MainWindow){
ui->setupUi(this);
QObject::connect(ui->actionCargar_imagen_1, SIGNAL(triggered()),this, SLOT(buscarImagen1()));
QObject::connect(ui->actionCargar_imagen_2, SIGNAL(triggered()),this, SLOT(buscarImagen2()));
QObject::connect(ui->actionCargar_imagen_3, SIGNAL(triggered()),this, SLOT(buscarImagen3()));
QObject::connect(ui->Fusion, SIGNAL(valueChanged(int)),this, SLOT(ponderar()));
QObject::connect(this, SIGNAL(filtrar1(int)),this, SLOT(mostrarImagen4()));
QObject::connect(this, SIGNAL(filtrar2(int)),this, SLOT(mostrarImagen5()));
QObject::connect(this, SIGNAL(filtrar3(int)),this, SLOT(mostrarImagen6()));
QObject::connect(this, SIGNAL(imagenLista(int)),this, SLOT(cargarImagen(int)));
QObject::connect(ui->btn_Filtrar, SIGNAL(released()),this, SLOT(filtrarImagen()));
QObject::connect(ui->RedSlider, SIGNAL(valueChanged(int)),this,SLOT(colorPlano()));
QObject::connect(ui->BlueSlider, SIGNAL(valueChanged(int)),this,SLOT(colorPlano()));
QObject::connect(ui->GreenSlider, SIGNAL(valueChanged(int)),this,SLOT(colorPlano()));
QObject::connect(this, SIGNAL(cambiocolor()),this, SLOT(mostrarImagen7()));
QImage imagenes[8];
for(int i=0;i<8;i++){
imagenes[i]=QImage();
}
}
////////////////////////////////////////////////////////////////
void MainWindow::buscarImagen1(){
QString fileName = QFileDialog::getOpenFileName(this, tr("Abrir Imagen"), "./", tr("Imagen (*.png *.jpg *.jpeg *.bmp *.ppm);; All files (*.*)"));
if(fileName == "") return;
//emit ruta1(fileName);
emit textoListo(fileName);
imagenes[0] = QImage(fileName);
imagenes[0]= imagenes[0].scaled(170,170);
if(imagenes[0].isNull()){
QMessageBox::information(this, tr("Error de carga!!"),tr("No se puede cargar %1. ").arg(fileName));
imagenes[0] = QImage();
return;
}
ui->Ruta1->setText(fileName);
emit imagenLista(0);
}
void MainWindow::buscarImagen2(){
QString fileName = QFileDialog::getOpenFileName(this, tr("Abrir Imagen"), "./", tr("Imagen (*.png *.jpg *.jpeg *.bmp *.ppm);; All files (*.*)"));
if(fileName == "") return;
//emit ruta2(fileName);
emit textoListo(fileName);
imagenes[1] = QImage(fileName);
imagenes[1]= imagenes[1].scaled(170,170);
if(imagenes[1].isNull()){
QMessageBox::information(this, tr("Error de carga!!"),tr("No se puede cargar %1. ").arg(fileName));
imagenes[1] = QImage();
return;
}
ui->Ruta2->setText(fileName);
emit imagenLista(1);
}
void MainWindow::buscarImagen3(){
QString fileName = QFileDialog::getOpenFileName(this, tr("Abrir Imagen"), "./", tr("Imagen (*.png *.jpg *.jpeg *.bmp *.ppm);; All files (*.*)"));
if(fileName == "") return;
//emit ruta3(fileName);
emit textoListo(fileName);
imagenes[2] = QImage(fileName);
imagenes[2]= imagenes[2].scaled(170,170);
if(imagenes[2].isNull()){
QMessageBox::information(this, tr("Error de carga!!"),tr("No se puede cargar %1. ").arg(fileName));
imagenes[2] = QImage();
return;
}
ui->Ruta3->setText(fileName);
emit imagenLista(2);
}
///////////////////////////////////////////////////////////////
void MainWindow::mostrarImagen4(){
emit imagenLista(4);
}
void MainWindow::mostrarImagen5(){
emit imagenLista(5);
}
void MainWindow::mostrarImagen6(){
emit imagenLista(6);
}
///////////////////////////////////////////////////////////////scrollArea_1
void MainWindow::cargarTexto(QString texto){
ui->Ruta1->setText(texto);
}
///////////////////////////
void MainWindow::cargarImagen(int area) {
QImage *out = new QImage(imagenes[area]);
QLabel *label = new QLabel;
label->setPixmap(QPixmap::fromImage(*out, Qt::AutoColor));
if (area == 0) ui->scrollArea_1->setWidget(label);
if (area == 1) ui->scrollArea_2->setWidget(label);
if (area == 2) ui->scrollArea_3->setWidget(label);
if (area == 3) ui->scrollArea_4->setWidget(label);
if (area == 4) ui->scrollArea_5->setWidget(label);
if (area == 5) ui->scrollArea_6->setWidget(label);
if (area == 6) ui->scrollArea_7->setWidget(label);
if (area == 7) ui->scrollArea_8->setWidget(label);
}
//////////////////////////////////////////////////////////////
void MainWindow::filtrarImagen(){
int R,G,B;
QColor pixelRGB;
imagenes[4]=imagenes[0];
if(imagenes[4].isNull()) imagenes[4] = QImage();
imagenes[5]=imagenes[1];
if(imagenes[5].isNull()) imagenes[5] = QImage();
imagenes[6]=imagenes[2];
if(imagenes[6].isNull()) imagenes[6] = QImage();
for(int k=0;k<3;k++){
if (imagenes[k].isNull()) continue;
for(int i=0;i<imagenes[k].height();i++){
for(int j=0;j<imagenes[k].width();j++){
pixelRGB=imagenes[k].pixelColor(i,j);
R = pixelRGB.red();
G = pixelRGB.green();
B = pixelRGB.blue();
if(ui->Tresched_chBox->isChecked()){
if(R < ui->RedSlider->value()){
R=0;
}
if(G < ui->GreenSlider->value()){
G=0;
}
if(B < ui->BlueSlider->value()){
B=0;
}
}
if(ui->Tresched_chBox->isChecked()==false){
if(R > ui->RedSlider->value()){
R=0;
}
if(G > ui->GreenSlider->value()){
G=0;
}
if(B > ui->BlueSlider->value()){
B=0;
}
}
//printf("(%i,%i,%i)",R,G,B);
imagenes[k+4].setPixelColor(i,j,QColor(R,G,B,0));
}
}
}
emit filtrar1(4);
emit filtrar2(5);
emit filtrar3(6);
}
//////////////////////////////////////////////////////////////
void MainWindow::ponderar(){
if((imagenes[1].isNull() == false) and (imagenes[2].isNull() == false)){
imagenes[3] = imagenes[2];
float ponderacion = (float) ui->Fusion->value();
QColor pixelRGB1,pixelRGB2;
int R1,G1,B1,R2,G2,B2,R3,G3,B3;
int alfa1,alfa2,alfa3;
for(int i=0;i<imagenes[1].height();i++){
for(int j=0;j<imagenes[1].width();j++){
pixelRGB1=imagenes[1].pixelColor(i,j);
R1 = pixelRGB1.red();
G1 = pixelRGB1.green();
B1 = pixelRGB1.blue();
alfa1 = pixelRGB1.alpha();
pixelRGB2=imagenes[2].pixelColor(i,j);
R2 = pixelRGB2.red();
G2 = pixelRGB2.green();
B2 = pixelRGB2.blue();
alfa2 = pixelRGB2.alpha();
R3=(R1*ponderacion/100.0 + R2*(100.0-ponderacion)/100.0);
G3=(G1*ponderacion/100.0 + G2*(100.0-ponderacion)/100.0);
B3=(B1*ponderacion/100.0 + B2*(100.0-ponderacion)/100.0);
alfa3=(alfa1*ponderacion/100.0 + alfa2*(100.0-ponderacion)/100.0);
//printf("(%i,%i,%i)",R3,G3,B3);
imagenes[3].setPixelColor(i,j,QColor(R3,G3,B3,alfa3));
}
}
emit imagenLista(3);
}
}
//////////////////////////////////////////////////////////////
void MainWindow::colorPlano(){
imagenes[7] = QImage(175,175,QImage::Format_RGB32);
int R,G,B;
R = ui->RedSlider->value();
G = ui->GreenSlider->value();
B = ui->BlueSlider->value();
for(int i=0;i<imagenes[7].height();i++){
for(int j=0;j<imagenes[7].width();j++){
imagenes[7].setPixelColor(i,j,QColor(R,G,B));
}
}
emit cambiocolor();
emit imagenLista(7);
}
//////////////////////////////////////////////////////////////
MainWindow::~MainWindow(){
delete ui;
}
/////////////////////////////////////////////
The rest of the code is on the link on the top of this question.
Thank you for helping me, I'm new to Ubuntu, qt and C++ and I want to improve, but it's quite frustrating when every solution generates another error.

It seems that your source folder contains obsolete build products from another system. Modern Qt Creator never puts those output files inside of the source folders. Close Qt Creator, then remove all files other than the below:
Ayudantia2.pro
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
marge.jpeg
pdi.jpeg
The files above must be the only files left in the source folder. Make sure you don't miss the hidden files, specifically remove:
.qmake.stash remove
Then open Qt Creator, open the project, configure it for the current Qt version, and attempt building again.

Related

Qt Serial with Arduino Due Native USB port and Bluetooth NR 42 configuring through Xbee explorer

I am trying to make an application in Qt to configure a bluetooth module RN42 http://ww1.microchip.com/downloads/en/DeviceDoc/rn-42-ds-v2.32r.pdf . In order to configure the module some command have to be sent via serial port, but here is where the extrange things start happening. I conecto it to the computer via xbee xplorer and I can configure it without any problems using my application, but when I try to retreive the current configuration no response is got, I can see that the device enters in configuration mode because the led blinks faster, but I cannot get any feedback from the device via serial port.
So I decided to start debugging with arduino due, if I connect it via programming port I can comunicate wihout problems, but if I connect it with the USB native port I do not get any information from the device. But if I open the port with the arduino serial monitor, the comunication starts, then close the arduino serial monitor, open my application and I am comunicating without problems.
I have also tried to comunicate with docklight (a serial monitor application) and again I have no problem comunicating, but if after comunicating with docklight I try to comunicate with my application no response will be got, unlike arduino serial monitor.
Eventhough I debugged with an oscilloscope and I can see that the information is sent once the port is closed.
I have tried many different things and I do not know what I am doing wrong. I tink it is related with the configuration of the port, but not sure, could it be a bug with the QtSerialport?
Here are my programs. I am using Qt creator 5.9.1 in windows with MinGW53_32
QT
.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-07-25T08:39:59
#
#-------------------------------------------------
QT += core gui
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = BT_Config_Tool
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
bluetooth_config.cpp
HEADERS += \
bluetooth_config.h
FORMS += \
bluetooth_config.ui
bluetooth_config.h
#ifndef BLUETOOTH_CONFIG_H
#define BLUETOOTH_CONFIG_H
#include <QMainWindow>
#include <QTimer>
#include <QSerialPort>
#include <QtSerialPort>
#include <QtSerialPort/QtSerialPort>
#include <stdio.h>
#include <math.h>
#include <QSerialPortInfo>
#define BUFFMAX 1000
namespace Ui {
class bluetooth_config;
}
class bluetooth_config : public QMainWindow
{
Q_OBJECT
public slots:
void ReadDevice(void);
void FlashDevice(void);
void UpdateCombobox(void);
void ReadSerial(void);
public:
explicit bluetooth_config(QWidget *parent = 0);
~bluetooth_config();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::bluetooth_config *ui;
QSerialPort *_port;
QTimer *_timerRead;
QTimer *_timerFlash;
QTimer *_timerUpdateCombobox;
QSerialPortInfo *_serialPortInfo;
int _cFlash = 0;
int _cRead = 0;
char _buffer[BUFFMAX];
//QByteArray _buffer;
int c;
};
#endif // BLUETOOTH_CONFIG_H
bluetooth_config.cpp
#include "bluetooth_config.h"
#include "ui_bluetooth_config.h"
const char *nameFlash;
const char *passFlash;
const char *nameRead;
char trama[BUFFMAX];
int item = 0;
bluetooth_config::bluetooth_config(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::bluetooth_config)
{
ui->setupUi(this);
ui->label_4->setVisible(false);
ui->label_5->setVisible(false);
_timerRead = new QTimer(this);
connect(_timerRead,SIGNAL(timeout()),this, SLOT(ReadDevice()));
_timerFlash = new QTimer(this);
connect(_timerFlash,SIGNAL(timeout()),this, SLOT(FlashDevice()));
_timerUpdateCombobox = new QTimer(this);
connect(_timerUpdateCombobox,SIGNAL(timeout()),this, SLOT(UpdateCombobox()));
_timerUpdateCombobox->start(2000);
_port = new QSerialPort();
_port->setBaudRate(QSerialPort::Baud115200);
_port->setDataBits(QSerialPort::Data8);
_port->setParity(QSerialPort::NoParity);
_port->setStopBits(QSerialPort::OneStop);
_port->setFlowControl(QSerialPort::NoFlowControl);
connect(_port,SIGNAL(readyRead()),this,SLOT(ReadSerial()));
//ui->tabWidget->setTabEnabled(0, false);
}
bluetooth_config::~bluetooth_config()
{
delete ui;
}
void bluetooth_config::ReadDevice()
{
_cRead ++;
if (_cRead == 1){
_port->write("$$$");
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
}
else if (_cRead == 2){
_port->write("---\r\n");
_port->waitForBytesWritten();
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
}
else if (_cRead == 3){
ui->label_5->setVisible(true);
ui->lcdNumber_2->display(_cRead);
_timerRead->stop();
_cRead = 0;
}
}
void bluetooth_config::FlashDevice()
{
_cFlash ++;
if (_cFlash == 1){
_port->write("$$$");
}
else if (_cFlash == 2){
nameFlash = ui->lineEdit->displayText().toUtf8().constData();
strcpy(trama, "SN,");
strcat(trama,nameFlash);
strcat(trama,"\n\r");
_port->write(trama);
}
else if (_cFlash == 3){
passFlash = ui->lineEdit_2->displayText().toUtf8().constData();
strcpy(trama, "SP,");
strcat(trama,passFlash);
strcat(trama,"\n\r");
_port->write(trama);
}
else if (_cFlash == 4){
_port->write("---\n\r");
}
else if (_cFlash == 5){
_cFlash = 0;
_timerFlash->stop();
ui->label_4->setVisible(true);
}
}
void bluetooth_config::UpdateCombobox()
{
item = ui->comboBox->currentIndex();
ui->comboBox->clear();
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts())
{
ui->comboBox->addItem(serialPortInfo.portName());
}
if (item <= (ui->comboBox->count() - 1) && item >= 0){
ui->comboBox->setCurrentIndex(item);
}
else {
ui->comboBox->setCurrentIndex(ui->comboBox->count() - 1);
}
}
void bluetooth_config::ReadSerial()
{
int ojete = _port->bytesAvailable();
ui->lcdNumber->display(ojete);
//_port->read(_buffer,BUFFMAX);
QByteArray a = _port->readAll();
//ui->plainTextEdit->appendPlainText(_buffer);
ui->plainTextEdit->appendPlainText(a);
if (_cRead == 1 || _cRead == 2){
_timerRead->start(50);
}
}
void bluetooth_config::on_pushButton_clicked()
{
ui->label_5->setVisible(false);
_timerRead->start(50);
_port->flush();
}
void bluetooth_config::on_pushButton_2_clicked()
{
ui->label_4->setVisible(false);
_timerFlash->start(50);
_port->flush();
}
void bluetooth_config::on_pushButton_3_clicked()
{
if (!_port->isOpen()){
_port->setPortName(ui->comboBox->currentText());
if (_port->open(QIODevice::ReadWrite)){
ui->label_3->setText("Puerto abierto");
ui->pushButton_3->setText("Cerrar");
ui->pushButton->setEnabled(true);
ui->pushButton_2->setEnabled(true);
}
else {
ui->label_3->setText("Ha ocurrido un error al abrir el puerto");
}
}
else {
_port->close();
ui->label_3->setText("Puerto cerrado");
ui->pushButton_3->setText("Abrir");
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(false);
}
}
main.cpp
#include "bluetooth_config.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bluetooth_config w;
w.show();
return a.exec();
}
Thank you very much.
Alejandro

Qt embedding MYSQL

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.

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

Qt 5.3 Can't make QCompass (QSensor) work on Windows 8.1

I can't make sensors works on my Asus Transformer T100.
Magnetometer and Compass don't start, and I have fake value from the accelerometer (always x=0, y=9.8, z=0).
I always get the same result, even with my laptop :
first textEdit:
Initialisation...
QAccelerometer is connected to backend...
QAccelerometer isActive...
Attente des données capteur...
Second textEdit:
ven. juin 6 14:56:41 2014
Acceleration: x = 0
y = 9.8
z = 0
Compass: UNAVAILABLE
QMagnetometer: UNAVAILABLE
And this code :
QList<QByteArray> sensorList = QSensor::sensorTypes();
ui->init->append("Sensor list length: " + QString::number(sensorList.size()).toUtf8());
foreach( QByteArray sensorName, sensorList ) {
ui->init->append("Sensor: " + sensorName);
}
Give me :
Sensor: QAmbientLightSensor
Sensor: QAccelerometer
Sensor: QTiltSensor
Sensor: QOrientationSensor
Sensor: QRotationSensor
Where is QCompass ? QMagnetometer ? Why QAccelerometer is faked ? :'(
Here is my simplified test-code, only with QCompass :
header:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QCompass>
#include <QCompassReading>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void update();
void error(int);
private:
Ui::MainWindow *ui;
QCompass *compass;
QCompassReading *compass_reading;
};
#endif // MAINWINDOW_H
code :
#include <QDateTime>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->init->setText("Initialisation...");
compass = new QCompass(this);
connect(compass, SIGNAL(readingChanged()), this, SLOT(update()));
connect(compass, SIGNAL(sensorError(int)), this, SLOT(error(int)));
compass->setDataRate(1);
compass->start();
if (compass->isBusy()) {
ui->init->append("QCompass is busy...");
}
if(compass->isConnectedToBackend()) {
ui->init->append("QCompass is connected to backend...");
}
if(compass->isActive()) {
ui->init->append("QCompass isActive...");
}
ui->init->append("Waiting for sensors...");
}
MainWindow::~MainWindow()
{
delete compass;
delete ui;
}
void MainWindow::update()
{
QString text_compass;
ui->textEdit->clear();
accel_reading = accel->reading();
compass_reading = compass->reading();
if(compass_reading != 0) {
text_compass = QDateTime::currentDateTime().toString() +
+ "\nCompass: azimuth = " + QString::number(compass_reading->azimuth());
+ "\ncalibration level = " + QString::number(compass_reading->calibrationLevel());
ui->textEdit->append(text_compass);
}
else {
text_compass = "\nCompass: UNAVAILABLE";
ui->textEdit->append(text_compass);
}
}
void MainWindow::error(int erreur) {
QMessageBox::critical(this, "Erreur", "Erreur num : " + QString::number(erreur).toUtf8());
}
The solution for now is to hack the winrt sensors plugin and rebuild it.
(the sensors backend for winrt works for windows 7/8 desktop application).
First git clone the plugin, or get Qt's source code.
then open src/plugins/sensors/sensors.pro and add these lines :
win32-msvc2012|win32-msvc2013 {
isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic dummy
}
winrt|win32-msvc2012|win32-msvc2013 {
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt
}
REMOVE this line :
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt
Then open src/plugins/sensors/winrt/winrt.pro and add this lines :
win32-msvc2012|win32-msvc2013: LIBS += -lruntimeobject
And finally run qmake, make/nmake, make/nmake install
(Ask google for more informations about how to build)
IMPORTANT : the run process should start from the directory where the qtsensors.pro file is (e. g. C:\Qt\5.4\Src\qtsensors).
To get more informations, and follow :
Link to the bug : https://bugreports.qt-project.org/browse/QTBUG-39590
Link to the patch : https://codereview.qt-project.org/#/c/87370/

How to catch exceptions with Qt platform independently?

I'm using boost::date_time in my project. When date is not valid it thorws std::out_of_range C++ exception. In Qt's gui application on windows platform it becomes SEH exception, so it doesn't catched with try|catch paradigm and programm dies. How can I catch the exception platform independently?
try{
std::string ts("9999-99-99 99:99:99.999");
ptime t(time_from_string(ts))
}
catch(...)
{
// doesn't work on windows
}
EDITED:
If somebody didn't understand, I wrote another example:
Qt pro file:
TEMPLATE = app
DESTDIR = bin
VERSION = 1.0.0
CONFIG += debug_and_release build_all
TARGET = QExceptExample
SOURCES += exceptexample.cpp \
main.cpp
HEADERS += exceptexample.h
exceptexample.h
#ifndef __EXCEPTEXAMPLE_H__
#define __EXCEPTEXAMPLE_H__
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <stdexcept>
class PushButton;
class QMessageBox;
class ExceptExample : public QMainWindow
{
Q_OBJECT
public:
ExceptExample();
~ExceptExample();
public slots:
void throwExcept();
private:
QPushButton * throwBtn;
};
#endif
exceptexample.cpp
#include "exceptexample.h"
ExceptExample::ExceptExample()
{
throwBtn = new QPushButton(this);
connect(throwBtn, SIGNAL(clicked()), this, SLOT(throwExcept()));
}
ExceptExample::~ExceptExample()
{
}
void ExceptExample::throwExcept()
{
QMessageBox::information(this, "info", "We are in throwExcept()",
QMessageBox::Ok);
try{
throw std::out_of_range("ExceptExample");
}
catch(...){
QMessageBox::information(this, "hidden", "Windows users can't see "
"this message", QMessageBox::Ok);
}
}
main.cpp
#include "exceptexample.h"
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
ExceptExample e;
e.show();
return app.exec();
}
Adding answer from the comments:
aschelper wrote:
Is your Qt library compiled with C++
exception support enabled? Sometimes
they're not, which causes problems.
hoxnox (OP) answered:
#aschelper I reconfigured Qt with
-exceptions option. It fixed situation. If you'll post the answer
I'll mark it as right.