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. Use c++ factory classes in qml

Use c++ factory classes in qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlfactory
6 Posts 3 Posters 2.1k 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.
  • S Offline
    S Offline
    stefan.b
    wrote on 3 Oct 2017, 16:28 last edited by
    #1

    Hi!

    I have 2 factory classes that i implemented in c++. The factories are the same class, but different instances.

    Let's from simplicity say that the both create QPushButtons, but with different properties. How would you use something like this in qml?

    Cheers,
    Stefan

    E 1 Reply Last reply 3 Oct 2017, 16:54
    0
    • S stefan.b
      3 Oct 2017, 16:28

      Hi!

      I have 2 factory classes that i implemented in c++. The factories are the same class, but different instances.

      Let's from simplicity say that the both create QPushButtons, but with different properties. How would you use something like this in qml?

      Cheers,
      Stefan

      E Offline
      E Offline
      Eeli K
      wrote on 3 Oct 2017, 16:54 last edited by
      #2

      @stefan.b Can you give a specific use case? QML isn't class based as C++ is and is very dynamic, I don't think there's need for the factory design pattern. If you need QML push buttons with different properties you just create push buttons with different properties.

      1 Reply Last reply
      2
      • S Offline
        S Offline
        stefan.b
        wrote on 3 Oct 2017, 22:08 last edited by stefan.b 10 Mar 2017, 22:09
        #3

        Well this push button example is maybe a bit oversimplified...

        I want to make a HMI for several production machines, where all of them are controlled via 1 application.
        The machine software is written in Beckhoff Twincat 3 - a soft sps. For interfacing with the machines I am using a c library provided by Beckhoff that I nicely wrapped to c++. The c library uses unique keys to establish connections to machines. Then variables of these machines can be read and written. Additionally, notifications can be send from the machines whenever variables are changed within the machine.

        My wrapper uses a factory class for each machine (the factory class has the unique id of a machine as parameter). Variables are implemented as an object as well. For instance, if I want to read a value of a machine I can do something like this

        SpsManager *manager = new SpsManager('10.100.5.5.1.2:852'); // create manager class for machine, unique id as parameter
        SpsVariable *variable = manager->connectVariable('MAIN.temperature');
        variable->read().toString();

        The SpsVariable class has signals that can be connected to a line edit. (Whenever the variable changes, the text in the line edit will change as well) The variables in the machine can also be of type bool and can so be connected to a QPushButton (for instance, to start the machine)

        The c++ part as described above is implemented and works just fine and if I write the HMI in c++ using qtdesigner everything works. However, I would rather like to write the actual user interface with QML.

        I hoped I could explain my scenario well enough ...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Oct 2017, 21:52 last edited by
          #4

          Hi and welcome to devnet,

          So in the end you would need access to the SpsVariable object in your QML code, correct ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stefan.b
            wrote on 15 Oct 2017, 19:55 last edited by
            #5

            I need to create these objects in qml code and zehn connect them to different qml objects via signals.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Oct 2017, 20:09 last edited by
              #6

              Then why not make your manager a context object of your QQmlEngine instance and then use it in your QML code to retrieve the objects you need ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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