how can i access to SetContextProperty from Multiple classes
-
@dziko147 said in how can i access to SetContextProperty from Multiple classes:
how can i do this
otherClassInstance.SetContextProperty(...); // Or if otherClassInstance is a pointer otherClassInstance->SetContextProperty(...);
Or what is the question?
-
@dziko147 said in how can i access to SetContextProperty from Multiple classes:
what i need is to get the m_back in another class
Why do you need it in another class?
But if you really need it there then implement a setter method in that class and call it passing m_back as parameter. -
@jsulm I will explain you the situation and suggest me a way to solve it .
So , I display (radialbars) in a qml file using a Qquickwidget . I set Q_property , setter , getter , Notify method in backend class . then I would like to command this radialbars . So I create a command class .Currently I have this code :
in My Mainwindow
m_ui->quickWidget->rootContext()->setContextProperty("backend", &m_back);
In my command.cpp
QString Mode= ui->modecommande->currentText(); // this is a combobox qDebug() << Mode << "this is Mode select commande" ; m_back.setdirectiontext(Mode); // this is my problem
Is it clear for you ?
-
@dziko147 said in how can i access to SetContextProperty from Multiple classes:
Is it clear for you ?
It is clear for me that you don't understand anything about C++ programming:
- you don't know what a class is
- you don't know what a variable is
- you don't know what a class methods and attributes are
- you don't know what getter/setter functions are
So please, first learn C++ basics and then you will understand what you have to do and how!
-
@dziko147 said in how can i access to SetContextProperty from Multiple classes:
Is it clear for you ?
It is clear to you what I suggested?
Also, why do you need to set whole m_back in other class? This is bad design. From the code you posted you only need to share Mode. This is as easy as:void MainWindow::setMode(const QString& mode) { m_back.setdirectiontext(mode); } // command.cpp QString Mode= ui->modecommande->currentText(); // this is a combobox qDebug() << Mode << "this is Mode select commande" ; mainWindow->setMode(Mode);
Even better would be to use signals/slots here, so the command does not have to know anything about MainWindow. But I let it as exercise...