Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how can i access to SetContextProperty from Multiple classes
Forum Updated to NodeBB v4.3 + New Features

how can i access to SetContextProperty from Multiple classes

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 3 Posters 760 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dziko147

    Hello ,
    I want access a SetContextProperty from another class .
    how can i do this .
    thank you

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @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?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dziko147
      wrote on last edited by
      #3

      @jsulm thanks for your reply .

      m_ui->quickWidget->rootContext()->setContextProperty("backend", &m_back);
      
      

      what i need is to get the m_back in another class .

      i am not pro in c++ development . So excuse me if my question is stupid :)

      jsulmJ 1 Reply Last reply
      0
      • D dziko147

        @jsulm thanks for your reply .

        m_ui->quickWidget->rootContext()->setContextProperty("backend", &m_back);
        
        

        what i need is to get the m_back in another class .

        i am not pro in c++ development . So excuse me if my question is stupid :)

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 2 Replies Last reply
        0
        • jsulmJ jsulm

          @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.

          D Offline
          D Offline
          dziko147
          wrote on last edited by
          #5

          @jsulm thank you for your suggestion

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dziko147
            wrote on last edited by
            #6

            who can provide me an example please :)

            jsulmJ 1 Reply Last reply
            0
            • D dziko147

              who can provide me an example please :)

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @dziko147 What is so spetial about it?
              You know how to implement a method with a parameter in C++ and how to call it then? This is really very basic C++.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @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.

                D Offline
                D Offline
                dziko147
                wrote on last edited by
                #8

                @jsulm I will explain you the situation and suggest me a way to solve it .
                Inkeddebile_LI.jpg
                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 ?

                KroMignonK jsulmJ 2 Replies Last reply
                0
                • D dziko147

                  @jsulm I will explain you the situation and suggest me a way to solve it .
                  Inkeddebile_LI.jpg
                  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 ?

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #9

                  @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!

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  1
                  • D dziko147

                    @jsulm I will explain you the situation and suggest me a way to solve it .
                    Inkeddebile_LI.jpg
                    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 ?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @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...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dziko147
                      wrote on last edited by
                      #11

                      @jsulm ok now it's clear for me what should I do .
                      thank you :)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved