Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change the properties of qml with cpp in run*time
Forum Updated to NodeBB v4.3 + New Features

Change the properties of qml with cpp in run*time

Scheduled Pinned Locked Moved General and Desktop
29 Posts 2 Posters 11.2k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AcerExtensa
    wrote on last edited by
    #16

    I can't read your mind! Which error??? Something about QDebug? Add #include <QDebug>

    God is Real unless explicitly declared as Integer.

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #17

      emit this->fullname_changed(this->fname);

      This is giving an error

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #18

        Which error???

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #19

          expected token ; got this-> i tried several things but not workin

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #20

            Can you just copy the whole error here?
            Delete "this->" or delete whole emit statement it is not relevant in this example....

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #21

              Can u help me with this example. I understand this better.
              .qml file
              @Rectangle {
              id:rect1
              signal dataRequired;
              signal onchangecolor;
              width:250
              height:250

              function updateData(text) { dataText.text = text}  // slot
              function updatecolor(color){rect1.color="red"}
              
              anchors.fill: parent; color: "black"
              
              Text {
                  id: dataText
                  anchors.centerIn: parent; color: "white"
              }
              
              MouseArea {
                  anchors.fill: parent
                  onClicked:[ dataRequired(),
                      onchangecolor()]
              }
              

              }@

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #22

                @#include <QApplication>
                #include <QGraphicsObject>
                #include <QDeclarativeView>
                #include "MyClass.h"

                int main(int argc, char *argv[])
                {
                QApplication app(argc, argv);

                MyClass myClass;
                
                QDeclarativeView view;
                view.setSource(QUrl("MyItem.qml"));
                view.show();
                view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
                
                QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());
                

                QObject::connect(rootObject, SIGNAL(dataRequired()), &myClass, SLOT(getData()));
                QObject::connect(&myClass, SIGNAL(data(QVariant)), rootObject, SLOT(updateData(QVariant)));

                return app.exec&#40;&#41;;
                

                }
                @

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #23

                  @#ifndef MYCLASS_H
                  #define MYCLASS_H

                  #include <QObject>
                  #include <QVariant>

                  class MyClass : public QObject
                  {
                  Q_OBJECT

                  public:
                  MyClass() {}

                  public slots:
                  void getData() {
                  QString nm("Hello");
                  emit data(QVariant(nm));
                  }

                  signals:
                  void data(QVariant data);

                  };

                  #endif // MYCLASS_H
                  @

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #24

                    @Acerextensa: I want to change the color of the rectange using signals and slots cud u help me with the code or an idea. I tried this but could not understandt the concept. Thanks a ton for the help..:) I added the signal oncolorchange

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AcerExtensa
                      wrote on last edited by
                      #25

                      Pack your project in archive and load somewhere on the web. Don't forget to post the link.

                      God is Real unless explicitly declared as Integer.

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #26

                        http://www.file-upload.net/download-4697440/binding.zip.html

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          AcerExtensa
                          wrote on last edited by
                          #27

                          You have already done signal/slot connection for text in your code. Which concept do you not understand?

                          "binding.zip":http://vip2006.net/binding.zip

                          God is Real unless explicitly declared as Integer.

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #28

                            I know, that was an example. what should I do if i have to change the color of rectangle rect1, how should the property, function and signal be defined. say I want to change rect1 to yellow.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              AcerExtensa
                              wrote on last edited by
                              #29

                              Why can't you just read links I've posted for you?
                              Examples there, is exactly what you are asking here!

                              bq. The child could be located like this:
                              @ QObject rect = object->findChild<QObject>("rect");
                              if (rect)
                              rect->setProperty("color", "red");@

                              Just change the name of object in findChild function from "rect" to "rect1" that's all. Please read it! I would not help you anymore if you will ask question which already explained in examples from tutorials again... Sorry...

                              God is Real unless explicitly declared as Integer.

                              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