QtQuick2 does not find .h files with new classes - c++

I'm trying to learn how to connect Qt quick object signals to slots in classes in the c++ code. When I add the class definitions to the "qtquick2applicationviewer.h" file that is created by the system, everything works.
But I can't find a way to add my own .h file (I should do this as indicated in the .h file: "It is recommended not to modify this file, since newer versions of Qt Creator may offer an updated version of it.")
I tried adding the source to the .pro file (HEADERS += classes.h), also tried to add it to the .pri file (HEADERS += $$PWD/../classes.h) but no luck.
The Error I get is a linker error:
LNK2001: unresolved external sybol "public: virtual struct QMetaObject const * __thiscall MyClass::metaObject(void)const " (?metaObject#Myclass##UBEPBUQMetaObject##XZ)
and two more similar.
Any inputs on what I'm doing wrong is highly appreciated :)
Can probably help many others as well as it is a general question bases on the QTQuick tutorial application.
//classes.h
#ifndef CLASSES_H
#define CLASSES_H
#include <QObject>
#include <QVariant>
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *QMLObject) : m_QMLObject(QMLObject) {}
public slots:
void handleClick() {
m_QMLObject->setProperty("text", "Qt was here");
}
protected:
QObject *m_QMLObject;
};
#endif // CLASSES_H
//main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "classes.h"
#include <QtQuick>
#include <QtDebug>
void MyClassInQtQhfile::cppSlot(const QString &msg) {
qDebug() << "Called the C++ slot with message:" << msg;
}
int main(int argc, char *argv[])
{
QTextStream out(stdout);
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/Transitions/main.qml"));
viewer.showExpanded();
QObject *rectangle = viewer.rootObject()->findChild<QObject*>("rectangle");
QObject *text = viewer.rootObject()->findChild<QObject*>("text");
MyClassInQtQhfile *myClassInQtQhfile = new MyClassInQtQhfile();
MyClass *myclass = new MyClass(text);
QObject::connect(rectangle, SIGNAL(qmlSignal(QString)),
myClassInQtQhfile, SLOT(cppSlot(QString)));
QObject::connect(rectangle, SIGNAL(qmlSignal(QString)),
myclass, SLOT(handleClick()));
//rectangle is the object name, which needs to be define in qml for the component.e.g. objectName: "rectangle"
return app.exec();
}
//QML object sending signal
Rectangle {
objectName: "rectangle"
id: bottomLeftRect
width: 64
height: 64
color: "#00000000"
radius: 6
anchors.left: parent.left
anchors.leftMargin: 10
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
border.color: "#808080"
signal qmlSignal(string msg)
MouseArea {
id: mousearea3
anchors.fill: parent
onClicked:{
bottomLeftRect.qmlSignal("Hello from QML")
onClicked: page.state = 'State2'
}
}
}
Beginning of qtquick2applicationviewer.pri
# checksum 0x21c9 version 0x90005
# This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
# The code below adds the QtQuick2ApplicationViewer to the project and handles
# the activation of QML debugging.
# It is recommended not to modify this file, since newer versions of Qt Creator
# may offer an updated version of it.
QT += qml quick
SOURCES += $$PWD/qtquick2applicationviewer.cpp
HEADERS += $$PWD/qtquick2applicationviewer.h
HEADERS += $$PWD/../classes.h
INCLUDEPATH += $$PWD
...
.pro file
# Add more folders to ship with the application, here
folder_01.source = qml/Transitions
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
classes.h

Related

QQuickWindow in shared lib auto close when show in QApplication

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")));
}

std::ANYTHING is not declared

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.

Invoke a QML function from C++

I am using Qt on my RPI3.
I found a QML example which is Tesla Car instrument cluster. You can access full code from here or here.
I successfully created a project and debugged it. Now I am trying to change a value in the QML code from C++ side. There is a timer in my C++ code every 30 seconds I am trying to change speed value in the QML code with using QMetaObject::inokeMethod(): function. I read all examples in here.
Here is my C ++ code
#ifndef MYTIMER_H
#define MYTIMER_H
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QTimer>
#include <QtDebug>
class MyTimer : public QObject
{
Q_OBJECT
public:
MyTimer();
QTimer *timer;
int i=0;
public slots:
void MySlot();
};
#endif // MYTIMER_H
#include "mytimer.h"
MyTimer::MyTimer()
{
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(MySlot()));
timer->start(10000);
}
void MyTimer::MySlot()
{
i++;
if(i==3)
{
i=0;
QQmlEngine engine;
QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/Speedometer.qml")));
QObject *object = component.create();
QVariant speeds=100;
QVariant returnedValue;
QMetaObject::invokeMethod(object,"speedNeedleValue",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, speeds));
qDebug() << "From QML"<< returnedValue.toString();
delete object;
}
}
Here is QML code:
import QtQuick 2.4
import QtGraphicalEffects 1.0
Rectangle {
color: "transparent"
SpeedNeedle {
id: speedoNeedle
anchors.verticalCenterOffset: 0
anchors.centerIn: parent
focus: true
Keys.onPressed: {
if (event.key == Qt.Key_A) {
speedNeedleValue(100)
drive()
}
}
function speedNeedleValue(speeds) {
speedoNeedle.value = speeds
return ": I am here"
}
}
If I press the "A" button my speedNeedleValue(); function is working. And in debug page I can get the return data return ": I am here".
Problem is I can't set the speeds argument with invoke function.
Here is the debug page:
"https://preview.ibb.co/kqpvWS/rpi.png"
Every time interrupt I can get "I am here". but I also get " JIT is disabled.... " warning too.
Thank you for your answers.

Displaying qml from c++ differs from what qmlscene shows

I'm try to run a basic program that displays a simple qml file through c++. The code for loading QQmlEngine etc looks like this:
#include <QQmlEngine>
#include <QQmlComponent>
#include <QDebug>
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlEngine engine;
QQmlComponent component(&engine);
QQuickWindow::setDefaultAlphaBuffer(true);
component.loadUrl(QUrl("qrc:///qmlFiles/main.qml"));
if ( component.isReady() )
component.create();
else
qWarning() << component.errorString();
QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(),SLOT(quit()));
return app.exec();
}
and the qml (simplified) file is:
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.0
ApplicationWindow
{
width:800
height:600
//background: "white"
visible:true
function selectFile()
{
fileChooser.visible=true;
}
menuBar:MenuBar {
Menu{
title:"File"
MenuItem{
text:"Choose File"
shortcut: "Ctrl+F"
onTriggered:{
selectFile();
}
}
MenuItem {
text:"Quit"
shortcut: "Ctrl+Q"
onTriggered: Qt.quit()
}
}
}
FileDialog{
id:fileChooser
visible:false
modality:Qt.WindowModal
title:"Choose data file"
onAccepted:{
console.log(fileChooser.fileUrls)
visible:false
}
onRejected:{
console.log("Cancel")
visible:false
}
}
}
When I run the file from terminal using qmlscene the displayed looks different than while running it from the c++ program.
My guess is that the C++ implementation is unable to use platform specific stuff (for example QFileDialog) and falls back to qml implementation of the stuff.
I guess I need to load the qml file differently, but how?
Turns out there is some overriding or something with QGuiApplication .
Changed it to QApplication and looks as nice as in qmlscene.

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.