Updating c++ data in Qml
-
@dziko147 said in Updating c++ data in Qml:
Yes I understood that back in UploadCSV.cpp and MainWindow are 2 different Item .
I tried to get back from MainWindow (create instance of Mainwindow in UploadCSV) .
But didn't work .
Please Can you suggest a way ?It is very difficult/impossible for me to help you, because I don't understand what you are trying to do.
Please describe your use case. -
@dziko147 said in Updating c++ data in Qml:
i have a button in Uploadcsv ui . When is clicket a signal is emmitted to status slot in backend .
Value is defined in backend .
So qml should update the c++ dataWhere do you create
UploadCSV
instance? -
@KroMignon No i didn't create a Uploadcsv instance ?
I dont need any uploadcsv instance -
@KroMignon when signal emmited from uploadcsv there is a slot in backend witch fill data. Then i called a setprepertycontext in mainwindow which integrate backend in qml file
-
Hi,
@dziko147 said in Updating c++ data in Qml:
@KroMignon No i didn't create a Uploadcsv instance ?
I dont need any uploadcsv instanceIf you don't need any instance of that class then why do you have it in your code ?
From the code you posted, why do you have two Backend instances ? One in MainWindow and one in UploadCSV ?
-
@SGaist yes two instance of Backend class.
the first in UploadCSV.cpp to emit signal when button clickedBackend *back = new Backend(); // I think that this line is the problem ? connect(ui->parambtn_2, SIGNAL(clicked()),back , SLOT(status()),Qt::QueuedConnection);
the second in mainwindow.cpp to create a contextproperty :
back = new Backend(); m_ui->quickWidget->rootContext()->setContextProperty("cppObject",back);```
-
And you expect these two unrelated instances to communicate between different widgets from your UI ?
-
@SGaist said in Updating c++ data in Qml:
expect these two unrelated instances to communicate between different widgets from your UI ?
no I mentioned that these two instances cause a problem.
So can you suggest a way to do this !
BTW UploadCSV is a QDialog , Backend is QObject .
when I create instance in UploadCSV.h it cause problem !
-
Review your application architecture. There's an issue with what is created where and how they interact with each other.
You seem to have an issue with the proper composition of your various classes and GUI elements.
-
Yes there is and was already suggested in your other threads. You need to properly create your objects hierarchy.
You were creating a MainWidget object in your dialog trying to get data from it while it was in fact created by a different instance.
You seem to reproduce a similar scheme here.
-
@dziko147 said in Updating c++ data in Qml:
In my situation , when I would like to create an Backend instance in UploadCSV to emit signal .
And create Backend instance in MainWindow to set a contextProperty .
what should I do .
Please :)You should first explain why you think you have to create a Backend instance in UploadCSV?
It is impossible to understand (for me) what is the purpose of this.
And emitting a signal which is connected to nothing, results to nothing. -
@KroMignon in uploadcsv ui , i have a button . I want to emit clicked signal connected to a slot in backend which change data (see my code please) .
-
@dziko147 said in Updating c++ data in Qml:
in uploadcsv ui , i have a button . I want to emit clicked signal connected to a slot in backend which change data (see my code please) .
Your code is incomprehensible!
Please learn C++ basics, like what are classes, class members, class methods and class instances.I don't understand what is your problem, on click event the method
status()
instanceback
which is created inUploadCSV.cpp
will be called and you should see a debug message on console.I don't understand why you expect anything on QML side as this instance is not exposed to QML.
-
@dziko147 said in Updating c++ data in Qml:
there is no one who did something like this ?
Again, explain what you want to do, not what you have done.
Because what you have done don't made sense.If you want to update the
Backend
instanceback
create inMainWindow
on button click inUploadCSV.cpp
, then you have to connect the click event with this instance, not create a new instance ofBackend
inUploadCSV.cpp
. -
@KroMignon if I understand you . I should create an MainWindow Instance in UploadCSV.cpp then I call the back defined in MainWindow ?
Is that ?