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. [Merged] Inheriting Ui::MainWindow to add QListWidgetItem to a give ListWidget
Forum Updated to NodeBB v4.3 + New Features

[Merged] Inheriting Ui::MainWindow to add QListWidgetItem to a give ListWidget

Scheduled Pinned Locked Moved General and Desktop
29 Posts 9 Posters 14.2k 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
    baysmith
    wrote on last edited by
    #20

    Remove the ui pointers and change the constructor to use
    @
    Ui::EditMedicationForm::setupUi(this);
    Ui::MainForm::setupUi(this);
    @

    or

    Remove the Ui::* inheritance and change the constructor to use
    @
    ui = new Ui::EditMedicationForm;
    ui->setupUi(this);
    mainUi = new Ui::MainForm;
    mainUi->setupUi(this);
    @

    Nokia Certified Qt Specialist.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      erapid
      wrote on last edited by
      #21

      U didn't setup mainUi, so mainUi->lst_Medication_List is a pointer to nowhere

      I'm sure Qt doesn't like to receive
      @ new QListWidgetItem( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )@ with broken parent

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #22

        It is not intended that setupUi() of two different Ui classes are called with the main QWidget (this). At best the resulting Ui will look strange. I cannot see any use for this either.

        You should have two classes, with .h and .cpp, for either EditMedicationForm and for MainForm.

        Your call to mainUi->lst_Medication_List crashes, because you did not call setupUi on mainUi, so the members of mainUi are not yet created.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • W Offline
          W Offline
          webmaster.skelton
          wrote on last edited by
          #23

          Ok i understand that, but i need to be able to access and modify widgets located in two different UIs, For example, i have a list widget in main form and EditMedicationForm is where the attributes are changed. So I click add new, a new form pops up, I enter the information into the field, and i click save, those attributes need to be added to the listWidget located on main form. now am i wrong or do i not need to have access to both UI's to do this( fyi, I have tried handleing this in the editMedicationForm.cpp as well, i continue to get a seg fault because it will not let me setup the UI as it inherits from a QDialog, not a QMainWindow. Is there a better way to access and modify widgets located in multiple forms? I simply want to add a listwidget item to mainform from data created in editmedicationform. Am i thinking about the incorrectly?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #24

            [quote author="webmaster.skelton" date="1291900962"]Ok i understand that, but i need to be able to access and modify widgets located in two different UIs, For example, i have a list widget in main form and EditMedicationForm is where the attributes are changed. So I click add new, a new form pops up, I enter the information into the field, and i click save, those attributes need to be added to the listWidget located on main form.[/quote]

            Make your ui/mainUi pointers public or declare the respective other class as friends. The members of the uic generated ui classes are public. So you can access them everywhere.

            [quote author="webmaster.skelton" date="1291900962"]now am i wrong or do i not need to have access to both UI's to do this( fyi, I have tried handleing this in the editMedicationForm.cpp as well, i continue to get a seg fault because it will not let me setup the UI as it inherits from a QDialog, not a QMainWindow. Is there a better way to access and modify widgets located in multiple forms? I simply want to add a listwidget item to mainform from data created in editmedicationform. Am i thinking about the incorrectly?[/quote]

            Be warned: it is common sense, that exposing implementation details to other classes (the ui elements add to that) is considered harmful. It is usually better that you have getters in your classes and forms (your QDialog based class to enter the data) to extract the data you need and provide them in an ui-independend form (Strings, numbers, maybe a small helper class/struct) and to provide a setter (slot) in the other class (MainForm) that does the task of adding the actual list item.

            Also, you can not have widgets located in multiple forms! A widget belongs to either exactly one form (as a child widget) or no form at all (that holds for top level widgets like windows, dialogs, etc.)

            Sorry, but I think you did not understand the whole concept about user interfaces, forms, widgets and that all. I strongly suggest you do some steps backwards and start with some tutorials and introductions to become comfortable with the basic design of Qt applications.

            As a rule of thumb: one ui-file (Designer created form) goes together with exactly one header file (.h) and exactly one C++ implementation file (.cpp) and results in exactly one new custom widget. You can use the widget in other source files by including the header file. Whatever you made public in the class definition is available there.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Franzk
              wrote on last edited by
              #25

              [quote author="Volker" date="1291902228"]As a rule of thumb: one ui-file (Designer created form) goes together with exactly one header file (.h) and exactly one C++ implementation file (.cpp) and results in exactly one new custom widget.[/quote]Agree. Only if you know exactly what you're doing you can somewhat deviate from this rule, however you should probably still step back and rethink your implementation.

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • W Offline
                W Offline
                webmaster.skelton
                wrote on last edited by
                #26

                ok thanks for the help.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  troubalex
                  wrote on last edited by
                  #27

                  Is the issue solved? Can I close the thread?

                  THE CAKE IS A LIE
                  Web Community Manager - Qt Development Frameworks

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #28

                    It should be merged with "this thread":http://developer.qt.nokia.com/forums/viewthread/2139/

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      webmaster.skelton
                      wrote on last edited by
                      #29

                      Yea it can be closed.

                      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