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. HOW TO...add vaiable to (C++) class definition
Forum Updated to NodeBB v4.3 + New Features

HOW TO...add vaiable to (C++) class definition

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 194 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    i like to have SINGLE QDialog ( subroject )
    and be able to have multiple forms attached / selectable to this single object.

    i other words
    how to modify QDialog class to pass a index to be able to imlement such index to use specific form.

    Here is "standard" QDialog code :

    Dialog::Dialog(QWidget *parent)
        : QDialog(parent)
        , ui(new Ui::Dialog)  builds single form 
    {
        ui->setupUi(this);     builds single form 
       test  access to form TOK 
        text = " Inotial accesas from constructor (app) ";
        ui->textEdit->append(text);
    }
    
    

    How do I "add index " to it and replace single , ui(new Ui::Dialog)?

    I need a real code or an example to ADD / pass an "index" as variable to C++ class.
    THANKS

    Pl45m4P 1 Reply Last reply
    0
    • A Anonymous_Banned275

      i like to have SINGLE QDialog ( subroject )
      and be able to have multiple forms attached / selectable to this single object.

      i other words
      how to modify QDialog class to pass a index to be able to imlement such index to use specific form.

      Here is "standard" QDialog code :

      Dialog::Dialog(QWidget *parent)
          : QDialog(parent)
          , ui(new Ui::Dialog)  builds single form 
      {
          ui->setupUi(this);     builds single form 
         test  access to form TOK 
          text = " Inotial accesas from constructor (app) ";
          ui->textEdit->append(text);
      }
      
      

      How do I "add index " to it and replace single , ui(new Ui::Dialog)?

      I need a real code or an example to ADD / pass an "index" as variable to C++ class.
      THANKS

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @AnneRanch said in HOW TO...add vaiable to (C++) class definition:

      How do I "add index " to it and replace single , ui(new Ui::Dialog)?

      As is so often the case, it is difficult to find out what's the idea behind all this and how we could help.
      And also as almost always, your topic title is somewhat off your actual problem, which makes it even more difficult to provide an appropriate answer.

      I'm trying:
      So you want multiple instances (= "copies") of your Dialog UI in a single class?!
      The way you thought of is terrible design and probably very hard to maintain.
      If you plan to use the same UI multiple times:
      Either create multiple instances of your dialog's content as widgets in a loop and put them in some container like QList or QVector. Then you can access them by index
      OR
      Just spawn multiples of your QDialog directly and also put them in some container before.

      If you are thinking of Dialog having different versions of "UI" and you want to switch between them (by your "index"), better use
      UiLoader or use a QStackedWidget as main widget for your Dialog and add your "UIs" as page widgets to it.
      QStackedWidget also provides indices to select a matching page at runtime.

      (See this topic here)

      I need a real code

      What is unreal code anyway?! :)

      example to ADD / pass an "index" as variable to C++ class.

      This and your topic title would lead to something like this:

      Dialog::Dialog(int index, QWidget *parent)
          : QDialog(parent)
          , index_(index)
          , ui(new Ui::Dialog)
      

      but I dont think that's all your issue is about...


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2

      • Login

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