Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How can I create multiple, distinct instances of the same user instance represented by a .ui file?
Forum Updated to NodeBB v4.3 + New Features

How can I create multiple, distinct instances of the same user instance represented by a .ui file?

Scheduled Pinned Locked Moved Solved Qt 6
4 Posts 3 Posters 544 Views 2 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.
  • T Offline
    T Offline
    tamirmichael
    wrote on last edited by tamirmichael
    #1

    Hello and thanks for taking the time,
    In my application I need many (>40) instances of the same form, but at the same time each instance should maintain a distinct status (in terms of its contents, i.e. checkboxes etc.).
    If I create a single .ui file instead of a .ui file per instance (they have a slightly different function, so also different names but functionally they are the same), the user interface ingredients are no longer unique so instances impact one another. On the other hand, having multiple .ui files seems redundant and wasteful.
    If there a way to do this using one .ui file to represent multiple instances?
    Thanks in advance.

    CP71C 1 Reply Last reply
    0
    • T tamirmichael

      Hello and thanks for taking the time,
      In my application I need many (>40) instances of the same form, but at the same time each instance should maintain a distinct status (in terms of its contents, i.e. checkboxes etc.).
      If I create a single .ui file instead of a .ui file per instance (they have a slightly different function, so also different names but functionally they are the same), the user interface ingredients are no longer unique so instances impact one another. On the other hand, having multiple .ui files seems redundant and wasteful.
      If there a way to do this using one .ui file to represent multiple instances?
      Thanks in advance.

      CP71C Offline
      CP71C Offline
      CP71
      wrote on last edited by
      #2

      @tamirmichael
      Hi,
      I suppose that for your Form you have (for example):
      a MyForm.ui
      a MyForm class that is declared in MyForm.h and MyForm.cpp files

      So, an one a possible way is:

      MyForm *form1 = new MyForm(this);
      MyForm *form2 = new MyForm(this);

      You can declare functions to customize every instance, for example:
      form1->setCustom1();
      form2->setCustom2();

      or

      form1->setCustom( mode1 );
      form2->setCustom( mode2 );

      You can send a signal from instance to other instance, for example
      connect( form1, &MyForm::sendData, form2, &MyForm::receiveData );
      connect( form1, &MyForm::sendData, form2, &MyForm::receiveData );

      Made for two, made for N instances ;)

      Note: do not use static variables in your MyForm for customization.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Out of curiosity, do you really need that many instances of your widget ?

        It looks like using the model view paradigm might simplify your UI handling.

        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
        • T Offline
          T Offline
          tamirmichael
          wrote on last edited by tamirmichael
          #4

          Thank you for replying. The actual reason for the problem is not the optimization I implemented (i.e. removing the majority of the .ui files) but due to actively, explicitly resetting the checkboxes...problem solved, all is good!

          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