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. [Solved] setContextProperty and Inheritance

[Solved] setContextProperty and Inheritance

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • L Offline
    L Offline
    luke_dirtwalker
    wrote on last edited by
    #1

    Hi,

    I have an UiHandlerClass which has a lot of Function which are the same except from the name string in setContextProperty.

    As the class got to big anyway i decided to split the class in 2 classes which share a lot of code. So i thought of an abstractClass which
    has a function say: setStation() and in the both subclasses i can call this function. But the need to set differnet Properties. Thus i wanted to know if there is a way that in subclasses i can just define the name for the property withou changing the parent code.

    I hope of something like this

    @
    //file parent
    #define NAME "parent"

    class Parent{
    public:
    setStation(){
    //some code
    context->setContextProperty(NAME,someObj);
    }
    protected:
    SomeType someObj;
    }

    //in Child file
    #define NAME "childName"
    class Child : public Parent{

    }
    @

    such that qml can see properties with childName
    but with defines it doesn't work..

    I there some clean way to do this?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on last edited by
      #2

      You should create variable in Parent class and initialize its value in constructors with different values in Parent and Child. Overall learn about C++ inheritance.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luke_dirtwalker
        wrote on last edited by
        #3

        Ah nice, I had the idea of doing it with variables but I somehow thought these Strings need to be fixed at compile-time, thus i didn't even try it.

        This is actually very cool 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