Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. What is the big picture around Object Oriented Programming? Can you let users create objects?
Forum Updated to NodeBB v4.3 + New Features

What is the big picture around Object Oriented Programming? Can you let users create objects?

Scheduled Pinned Locked Moved Unsolved The Lounge
18 Posts 5 Posters 3.3k 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.
  • D DevinQT

    @mrjj
    Okay apparently i need to do some huge reconceptualisation then of what the big picture of an application is in my head..

    So. What would something like, for example, a layer in Photoshop be then? How is data/variables for each layer stored? Like the layer's name and the layer's opacity value? Each layer has to have it's own variables that control these aspects right? And i think that when an object is created each variables implemented in a class is getting his own version of that variable related to that specific object. But how is that done without objects?

    And in many tutorials i've seen about classes, classes are always presented with simple (console app) usage examples like a 'person'.. with things like 'name', 'age' and 'gender' instantiated through the constructor.. or maybe books.. with 'title', 'genre', and 'releaseDate' instantiated through the constructor... So i always assumed that a user could add 'persons' with an app, like you can in an app for managing contacts, or clients or ebooks for that matter.

    But what are these contacts then, in apps where you can create new contacts? How are these 'persons' and their variables stored, if they are not objects? Do these examples, so often used in tutorials about classes, only relate to 'persons' predefined for usage in an application by the programmer, like the characters of a game?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #9

    @DevinQT
    Well yes a layer in photoshop would most likely be a class inside the program.
    So when use press New layer, program does
    Layer *Newlayer = new Layer();

    • So i always assumed that a user could add 'persons' with an app, like you can in an app for managing contacts, or clients or ebooks for that matter.

    Yes, they can. The application simply create new instances of that class.

    So in short, when using Object Oriented Programming, you center your application around classes
    like, the sample you mentions with Person etc.
    and each class keeps its own data and also methods that alters the data.
    In non Object Oriented Programming, the data and the methods that changes data, is not
    keep inside a class but are separate.

    Also, an Object might be able to draw on screen. LIke many can in Qt or be completely invisible to the user and
    only used internally by the application.
    However, its the use of classes and language features that makes it Object Oriented.

    D 1 Reply Last reply
    1
    • D Offline
      D Offline
      DevinQT
      wrote on last edited by DevinQT
      #10

      @mrjj
      Okay i think we're on the same page. (Glad i don't need to reconceptualize my whole idea of an app) The example of creating new layers something like the thing i try to express when i talk about the user 'creating' objects. (Of which the possibilities of creation and modification are of course predefined by us, the programmers).

      So in the case of Photoshop saying "Layer* Newlayer = new Layer();", how is this done? Does this mean new objects can be instantiated in functions or slots? How is, for example, the automatic naming of these new objects done? (Newlayer1, Newlayer2, Newlayer3 etc.) Is something like that is even possible. They can't have the same names right? And it seems like we must define the names of the objects using code.

      1 Reply Last reply
      0
      • mrjjM mrjj

        @DevinQT
        Well yes a layer in photoshop would most likely be a class inside the program.
        So when use press New layer, program does
        Layer *Newlayer = new Layer();

        • So i always assumed that a user could add 'persons' with an app, like you can in an app for managing contacts, or clients or ebooks for that matter.

        Yes, they can. The application simply create new instances of that class.

        So in short, when using Object Oriented Programming, you center your application around classes
        like, the sample you mentions with Person etc.
        and each class keeps its own data and also methods that alters the data.
        In non Object Oriented Programming, the data and the methods that changes data, is not
        keep inside a class but are separate.

        Also, an Object might be able to draw on screen. LIke many can in Qt or be completely invisible to the user and
        only used internally by the application.
        However, its the use of classes and language features that makes it Object Oriented.

        D Offline
        D Offline
        DevinQT
        wrote on last edited by DevinQT
        #11

        @mrjj

        Let's get really simple and really practical. I just wanna know if i need to know about new syntax or concepts..
        In this very simple console application example; I have this plain object :

        Topject::Topject(QObject *parent) : QObject(parent)
        {
            qDebug() << "Topject constructed" << endl;
        }
        

        And i want a new Topject to be born, initialized and constructed everytime the pushButton is clicked in my Widget:

        void Widget::on_pushButton_clicked()
        {
           ???????????????
        }
        

        How would i build this? I have to give a name to a object when i make it with programming... But not all these objects can have the same name right?

        aha_1980A 1 Reply Last reply
        0
        • D DevinQT

          @mrjj

          Let's get really simple and really practical. I just wanna know if i need to know about new syntax or concepts..
          In this very simple console application example; I have this plain object :

          Topject::Topject(QObject *parent) : QObject(parent)
          {
              qDebug() << "Topject constructed" << endl;
          }
          

          And i want a new Topject to be born, initialized and constructed everytime the pushButton is clicked in my Widget:

          void Widget::on_pushButton_clicked()
          {
             ???????????????
          }
          

          How would i build this? I have to give a name to a object when i make it with programming... But not all these objects can have the same name right?

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by aha_1980
          #12

          @DevinQT said in What is the big picture around Object Oriented Programming? Can you let users create objects?:

          How would i build this? I have to give a name to a object when i make it with programming... But not all these objects can have the same name right?

          Correct, but you can (for example) have a list of objects:

          // header file
          #include <QList>
          
          class Widget {
          // ...
          private:
            QList<Topject *> m_topjects;
          }
          

          Then in your function you can do this:

          void Widget::on_pushButton_clicked()
          {
             Topject *t = new Topject;
             m_topjects.append(t);
          }
          

          Regards

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • D Offline
            D Offline
            DevinQT
            wrote on last edited by DevinQT
            #13

            Allright that's nice. I didn't know about Lists. Thanks. 🙂

            Is every time the function is done executing the Topject *t resetted? So that it is every time i click a different Topject?

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

              The way it's implemented, the Tobject will be initialized the way it was written in the constructor, that's all.

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

              D 1 Reply Last reply
              1
              • SGaistS SGaist

                The way it's implemented, the Tobject will be initialized the way it was written in the constructor, that's all.

                D Offline
                D Offline
                DevinQT
                wrote on last edited by
                #15

                @SGaist
                I understand, but my question was; what is the function 't' in the slot function. It is the name of the object.. Is this name still intact when it's passed into a list? And if it is; is the next 't', created with the next click, a different 't' then the first one? Does 't' only last in the scope of the function?

                mrjjM 1 Reply Last reply
                0
                • D DevinQT

                  @SGaist
                  I understand, but my question was; what is the function 't' in the slot function. It is the name of the object.. Is this name still intact when it's passed into a list? And if it is; is the next 't', created with the next click, a different 't' then the first one? Does 't' only last in the scope of the function?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  @DevinQT
                  Hi
                  t is the variable name that points to the Topject
                  t is only know in that function since its being defined there

                  a new t variable is create each time on_pushButton_clicked is called.

                  the t name is not added to the list. its the variable name.
                  in the list - an index in the list- points to the Topject
                  One could say its the same as t. but only in concept. its
                  not t anymore. but points to the same thing as t did.

                  1 Reply Last reply
                  3
                  • D Offline
                    D Offline
                    DevinQT
                    wrote on last edited by DevinQT
                    #17

                    Allright that all clears the fog a bit. Thanks. 🙂

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jia28
                      Banned
                      wrote on last edited by jia28
                      #18
                      This post is deleted!
                      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