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.2k 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 Offline
    D Offline
    DevinQT
    wrote on last edited by
    #3

    I think my definition of an object is just an instance of a class?

    With a path in Adobe Illustrator i mean a vector line, with which you build your drawings. A vector line can have a stroke and a fill, etc etc. It is just an example of an application where the user can create and modify things (which i assume are object instances of classes).

    I mean when they use my application. Right now i've created objects only by programming but i have no idea how i could let the user make objects, and how to do automatic naming and stuff of objects.

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

      I think you might be mixing two concepts here.

      Your definition of objects is correct.

      What will your application do ? They don't create objects directly, your application does that depending on what your user asks it to do. For example if it's an image preview application, your application is going to create many different objects of the various classes needed to show the window containing the image the user wants to see.

      A short example is the QPixmap set on the QLabel used to show an image. QPixmap that will get a QString
      containing the path to the image file.

      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
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #5

        Hi
        Object Oriented Programming is not about what you see on the screen or what the user can or cannot do.
        Its about how the application is structured internally and how it is designed.
        Using objects, its allow the programmer to implement app features using methods/constructs
        supported by an objected orientated language that make the app solid, easy to extend and
        maintain. Those methods/constructs are encapsulation, abstraction, inheritance and polymorphism.

        This short video explains it very well.
        https://www.youtube.com/watch?v=pTB0EiLXUC8

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

          SGaist,
          Okay so the user indirectly creates objects by asking the program to create them right? Let's say we make an application where the user can let the user add rectangles (like the window for containing an image) in a grid form to an empty board by clicking a + button.

          How do we let the program create these rectangles?
          Where do we call and instantiate these new rectangle objects? Is it in a function thats in a slot linked to the clicked signal of the + putton? Who decides the name of new rectangles? This has to go automatic right? (rectangle 1, rectangle 2, rectangle 3 rec....... or something like that)

          I guess these are classes, because i imagine each rectangle has properties which have been implemented in the rectangle class. (Like stroke width, for example) Maybe we've made buttons that can modify these properties of the rectangles once one is selected.

          Mrjj,
          So no new objects are created in the course of interaction with a program by the user? Is it just a fixed thing that decides the aspects of a program, with no interactivity with the user. Are these 'rectangles' no object instances? I don't understand this yet. Can't these app features the programmer implements with methods not create new objects or modify existing objects instances 'activated' in a program?

          mrjjM 1 Reply Last reply
          0
          • D DevinQT

            SGaist,
            Okay so the user indirectly creates objects by asking the program to create them right? Let's say we make an application where the user can let the user add rectangles (like the window for containing an image) in a grid form to an empty board by clicking a + button.

            How do we let the program create these rectangles?
            Where do we call and instantiate these new rectangle objects? Is it in a function thats in a slot linked to the clicked signal of the + putton? Who decides the name of new rectangles? This has to go automatic right? (rectangle 1, rectangle 2, rectangle 3 rec....... or something like that)

            I guess these are classes, because i imagine each rectangle has properties which have been implemented in the rectangle class. (Like stroke width, for example) Maybe we've made buttons that can modify these properties of the rectangles once one is selected.

            Mrjj,
            So no new objects are created in the course of interaction with a program by the user? Is it just a fixed thing that decides the aspects of a program, with no interactivity with the user. Are these 'rectangles' no object instances? I don't understand this yet. Can't these app features the programmer implements with methods not create new objects or modify existing objects instances 'activated' in a program?

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

            @DevinQT
            Hi
            It has nothing to do with if user can create new objects or not. Not at all.
            Its about how the programmer can design and structure the program internally.
            So Object Oriented Programming does not define what user can do it the program or how he will do it.
            Its simply a way of structuring the internals of the program.
            A way of creating applications.

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

              @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 1 Reply Last reply
              0
              • 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