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

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
variableclass
11 Posts 3 Posters 2.5k 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
    SGaist
    Lifetime Qt Champion
    wrote on 13 Aug 2016, 06:39 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 13 Aug 2016, 14:13
    0
    • P Offline
      P Offline
      Phoenox
      wrote on 13 Aug 2016, 10:22 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
      • S SGaist
        13 Aug 2016, 06:39

        Hi,

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

        G Offline
        G Offline
        gabor53
        wrote on 13 Aug 2016, 14:13 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Aug 2016, 17:02 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 14 Aug 2016, 03:01
          0
          • S SGaist
            13 Aug 2016, 17:02

            By error do you mean an invalid input ?

            G Offline
            G Offline
            gabor53
            wrote on 14 Aug 2016, 03:01 last edited by
            #6

            Hi @SGaist
            yes, error means invalid input.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 14 Aug 2016, 18:54 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 15 Aug 2016, 00:17
              0
              • S SGaist
                14 Aug 2016, 18:54

                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 15 Aug 2016, 00:17 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 15 Aug 2016, 20:06 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 16 Aug 2016, 00:56
                  0
                  • S SGaist
                    15 Aug 2016, 20:06

                    What kind of fixes do you have in mind ?

                    G Offline
                    G Offline
                    gabor53
                    wrote on 16 Aug 2016, 00:56 last edited by
                    #10

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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 16 Aug 2016, 07:03 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

                      11/11

                      16 Aug 2016, 07:03

                      • Login

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