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. Using the same variable (and its value) in different classes
Forum Updated to NodeBB v4.3 + New Features

Using the same variable (and its value) in different classes

Scheduled Pinned Locked Moved Unsolved General and Desktop
variableclass
11 Posts 3 Posters 2.8k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    How are Review and Additem related ? What does each of these classes do ?

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

    G 1 Reply Last reply
    0
    • PhoenoxP Offline
      PhoenoxP Offline
      Phoenox
      wrote on last edited by Phoenox
      #3

      Well, I guess your class AddItem looks something like this:

      class Additem {
      public:
        QString name() const;
        void setName(const QString& name);
      private:
        QString name;
      }
      

      Review may then access and change it using the defined public methods, maybe like so:

      #include "Additem.h"
      
      void yourFancyMethod() {
        Additem item;
        QString itemName = item.name();     // << Here we read the name variable from Additem
        // ... Manipulate itemName ...
        item.setName(itemName);             // << Here we write the changed itemName back to the Additem object
      }
      

      By the way, this is one of the key concepts of object oriented programming: If you want to change the properties of objects, you do this via nicely defined interfaces, and do not manipulate their properties directly.
      If you are unsure about this, I recommend you read up on that, have a look at some tutorials on object oriented programming. Else managing your code will get pretty tedious the bigger it gets.

      1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        How are Review and Additem related ? What does each of these classes do ?

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #4

        @SGaist
        Additem is a form and Review is where the user can review the information entered in Additem. If there is an error Review sends the information back to Additem for the user to fix it.

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

          By error do you mean an invalid input ?

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

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            By error do you mean an invalid input ?

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #6

            Hi @SGaist
            yes, error means invalid input.

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

              In that case, you shouldn't allow invalid input from the start. What kind of input are you giving to your users ?

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

              G 1 Reply Last reply
              0
              • SGaistS SGaist

                In that case, you shouldn't allow invalid input from the start. What kind of input are you giving to your users ?

                G Offline
                G Offline
                gabor53
                wrote on last edited by
                #8

                @SGaist
                Hi,
                I was wrong. It is a catalog for collectibles. Review is supposed to give an option to the user to review the entries and if all entries correct are correct they can add itvto the database or if there is something to fix, it goes back to Additem where they can make changes.

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

                  What kind of fixes do you have in mind ?

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

                  G 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    What kind of fixes do you have in mind ?

                    G Offline
                    G Offline
                    gabor53
                    wrote on last edited by
                    #10

                    @SGaist
                    Like they missed something, or made a wrong choice.

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

                      AFAIU, these are not really errors in the sense of validation. Your user forgot to e.g. check an option in a multiple choice question but that doesn't count as "wrong" like he tried to put an invalid value. Thus I don't see the need to modify Additem back from Review.

                      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

                      • Login

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