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. Project "componentization"
Forum Updated to NodeBB v4.3 + New Features

Project "componentization"

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 549 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.
  • B Offline
    B Offline
    Bremenpl
    wrote on 11 Apr 2019, 20:01 last edited by
    #1

    Hello There,
    I have the following problem: I was developing a QML based application, it contained QML frontend and a lot of logic behind in the backend (c++ classic Qt). The communication between QML and C++ was done using QQmlContext (setContextProperty). The backend and frontend are quite in tact.

    Now I need to create a pure component out of the QML frontend part. Even though I have already extracted everything in a way, that I can create a new component in code, that contains all the features, there are still the Qt/C++ connections, so the components has to come with the c++ overhead. This doesn't feel right and at this point I don't know how to handle multiple instances of the component.

    My question is: are there any guidelines on creating complex components in QML? Specifically, in a way where there will be multiple instances of that component, while each of it, has to have an unique connection for data flow (multiple structures and arrays) with the c++ part.

    I know that this is a very generic question, I don't expect any specific answers. I think I am looking for some QML+Qt design pattern.

    I would appreciate all help.

    lprzenioslo.zut.edu.pl

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcarney
      wrote on 11 Apr 2019, 21:13 last edited by
      #2

      One idea is having a "generator" C++ object that spawns an instance of the appropriate object(s) when the component is created. However, after the object is created I don't know how to track the lifetime of the object inside the component. The lifetime would have to be associated with the component somehow. I know you have to be careful with object lifetime and qml accessing objects. qml likes to delete objects it thinks it owns.

      Another idea is to have a list of objects and the current object being used for a particular component would be an tracked by an index set in the component. Again there would be the lifetime issue. On a list you could have the component destroy the object by calling a method on the list however.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • F Offline
        F Offline
        fcarney
        wrote on 11 Apr 2019, 22:01 last edited by fcarney 4 Nov 2019, 22:01
        #3

        Maybe this is the way to do this:
        https://doc.qt.io/qt-5/qqmlcontext.html
        It looks like you can have multiple contexts defined. Each component can have its own context.

        C++ is a perfectly valid school of magic.

        B 1 Reply Last reply 12 Apr 2019, 11:36
        1
        • F fcarney
          11 Apr 2019, 22:01

          Maybe this is the way to do this:
          https://doc.qt.io/qt-5/qqmlcontext.html
          It looks like you can have multiple contexts defined. Each component can have its own context.

          B Offline
          B Offline
          Bremenpl
          wrote on 12 Apr 2019, 11:36 last edited by
          #4

          @fcarney Hello, thank you for answer. I Like your idea. I have also found a blog post with similar concept: https://evileg.com/en/post/305/

          lprzenioslo.zut.edu.pl

          1 Reply Last reply
          0

          1/4

          11 Apr 2019, 20:01

          • Login

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