Updating c++ data in Qml
-
@jsulm this is my situation.
My project compouned of 3 classes :
1/Mainwindow
2/backend
/UploadCSV
In Mainwindow :
1/ I have a quickwidget which integrate a qml file .
2/ I create a backend instance to get data from it and fill the QMl FileIn Backend
1/I have the defenition of my data (getter, setter, change slots).In UploadCSV
1/I have a button when it's clicked a slot in Backend will change some data .
2/After change data I would like to display it on QML .I hope it's clear
-
@jsulm this is my situation.
My project compouned of 3 classes :
1/Mainwindow
2/backend
/UploadCSV
In Mainwindow :
1/ I have a quickwidget which integrate a qml file .
2/ I create a backend instance to get data from it and fill the QMl FileIn Backend
1/I have the defenition of my data (getter, setter, change slots).In UploadCSV
1/I have a button when it's clicked a slot in Backend will change some data .
2/After change data I would like to display it on QML .I hope it's clear
@dziko147 said in Updating c++ data in Qml:
I hope it's clear
No, you did not answer my question, which is actually quite clear...
-
alright @jsulm
@dziko147 this does actually help
My project compouned of 3 classes :
1/Mainwindow
2/backend
/UploadCSV
In Mainwindow :
1/ I have a quickwidget which integrate a qml file .
2/ I create a backend instance to get data from it and fill the QMl FileIn Backend
1/I have the defenition of my data (getter, setter, change slots).In UploadCSV
1/I have a button when it's clicked a slot in Backend will change some data .
2/After change data I would like to display it on QML .I hope it's clear
some more required information:
- how do you expose backend to the qml context, and where (in your code)
- name of your backend and uploadcsv instances, and where they are defined
- does UploadCSV have its own UI components? do you mean that with "button"
I have the high suspicion that everything is centered in and around mainwindow already and its only a matter of connecting it. But truthfully code will help, it doesn't look like you have much yet, so post as much as you can
-
alright @jsulm
@dziko147 this does actually help
My project compouned of 3 classes :
1/Mainwindow
2/backend
/UploadCSV
In Mainwindow :
1/ I have a quickwidget which integrate a qml file .
2/ I create a backend instance to get data from it and fill the QMl FileIn Backend
1/I have the defenition of my data (getter, setter, change slots).In UploadCSV
1/I have a button when it's clicked a slot in Backend will change some data .
2/After change data I would like to display it on QML .I hope it's clear
some more required information:
- how do you expose backend to the qml context, and where (in your code)
- name of your backend and uploadcsv instances, and where they are defined
- does UploadCSV have its own UI components? do you mean that with "button"
I have the high suspicion that everything is centered in and around mainwindow already and its only a matter of connecting it. But truthfully code will help, it doesn't look like you have much yet, so post as much as you can
@J-Hilk
1/ I expose backend to qml like this :back= new Backend(); m_ui->quickWidget->setVisible(true); m_ui->quickWidget->rootContext()->setContextProperty("cppObject",back); m_ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); m_ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/qml/automotive.qml")));
2/ And UploadCSV in MainWindow just for show . I dont use UploadCSV in MainWindow
//BTW CAN i define the connect signal of UploadCSV button here ? void MainWindow::on_actionUpload_CSV_File_triggered() { uploadcsv = new UploadCSV(); uploadcsv->show(); }
3/ Yes Sure UploadCSV has a UI form .
-
@J-Hilk
1/ I expose backend to qml like this :back= new Backend(); m_ui->quickWidget->setVisible(true); m_ui->quickWidget->rootContext()->setContextProperty("cppObject",back); m_ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); m_ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/qml/automotive.qml")));
2/ And UploadCSV in MainWindow just for show . I dont use UploadCSV in MainWindow
//BTW CAN i define the connect signal of UploadCSV button here ? void MainWindow::on_actionUpload_CSV_File_triggered() { uploadcsv = new UploadCSV(); uploadcsv->show(); }
3/ Yes Sure UploadCSV has a UI form .
@dziko147 alright,
we are getting closer,
I assume this:
back= new Backend(); m_ui->quickWidget->setVisible(true); m_ui->quickWidget->rootContext()->setContextProperty("cppObject",back); m_ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); m_ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/qml/automotive.qml")));
is inside the MainWindow constructor ?
//BTW CAN i define the connect signal of UploadCSV button here ? void MainWindow::on_actionUpload_CSV_File_triggered() { uploadcsv = new UploadCSV(); uploadcsv->show(); }
The way you have it currently set up, you have to make the connect call here.
but that won't work quite yet.
- I assume the button you want to press, to update your backend is part of the UploadCSV ui ? Therefore
ui->parambtn_2
is the button you want to press and is part of the UploadCSV ui? - have you yet defined a (custom)signal inside the UploadCSV class ?
- I assume the button you want to press, to update your backend is part of the UploadCSV ui ? Therefore
-
If my assumptions are correct, I'm writing this before a response,
you can/should make the following changes:
inside
UploadCSV .h
add a custom signal, for example purpose we'll name it myCustomButtonClicked(),public: explicit UploadCSV(QObject *parent = nullptr); ..... signals: void myCustomButtonClicked();
inside UploadCSV.cpp constructor definition, after ui->setupUi(this), connect the button to the recently created signal:
{ ui->setupUi(this); connect(ui->parambtn_2, &QAbstractButton::clicked, this, &UploadCSV::myCustomButtonClicked); // this connects/forwards the button clicked signal to the class signal 'myCustomButtonClicked' }
in mainwindow constructor, instantiate the UploadCSV in the constructor and connect it to the backend:
{ ui->setupUi(this); back= new Backend(); m_ui->quickWidget->setVisible(true); m_ui->quickWidget->rootContext()->setContextProperty("cppObject",back); m_ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); m_ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/qml/automotive.qml"))); uploadcsv = new UploadCSV(); connect(uploadcsv, & UploadCSV:: myCustomButtonClicked, backend, &Backend::status); //status has to be public! }
your
on_actionUpload_CSV_File_triggered
now only contains this:void MainWindow::on_actionUpload_CSV_File_triggered() { uploadcsv->show(); }
let's see if that worked.
code my contain typos, so be aware :D
-
@J-Hilk said in Updating c++ data in Qml:
If my assumptions are correct, I'm writing this before a response,
Finally it works :D :D :D
-
@J-Hilk said in Updating c++ data in Qml:
If my assumptions are correct, I'm writing this before a response,
Finally it works :D :D :D