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. Qt development without object-oriented programming

Qt development without object-oriented programming

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 975 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.
  • M Offline
    M Offline
    Mick_1
    wrote on 16 Jun 2022, 13:02 last edited by
    #1

    Hello,
    I develop an application with Qt and sometimes I wonder if I'm doing it correctly.

    My program is quite linear, I press a button and I execute all the actions that follow to reach my goal. But I'm struggling with the object-oriented approach, dividing each action into distinct classes and managing the private/public attributes, the access methods to my attributes. I often need attributes from one class to another.

    In short, my program contains only classes and I wondered if this is normal or if it is common to use C++ as an imperative paradigm (like C).

    Can I do without object-oriented programming in C++ with Qt ?

    Thanks for your advices.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jun 2022, 18:08 last edited by
      #2

      Hi,

      That's rather an architecture issue. You do not need to create different objects for each and every action you want to execute.

      Usually you would start by creating units that represent different aspects of your application and then the objects that matches them.

      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
      • M Offline
        M Offline
        Mick_1
        wrote on 20 Jun 2022, 07:35 last edited by Mick_1
        #3

        Sorry I didn't answer before,

        What do you mean? I don't have a class by actions but per group of actions.
        For example, a class that takes care of the link with the GUI, a class for reading and extracting data in a given folder, a class that generates reports and a "Process" class.

        When we develop in object-oriented mode, we usually reuse our classes several times? Technically, I only need one instance of each class and a linear operation.

        Except from the class that bridges the gap between the GUI (QML) and C++, is it a mandatory to code only with classes?

        J 1 Reply Last reply 20 Jun 2022, 08:35
        0
        • M Mick_1
          20 Jun 2022, 07:35

          Sorry I didn't answer before,

          What do you mean? I don't have a class by actions but per group of actions.
          For example, a class that takes care of the link with the GUI, a class for reading and extracting data in a given folder, a class that generates reports and a "Process" class.

          When we develop in object-oriented mode, we usually reuse our classes several times? Technically, I only need one instance of each class and a linear operation.

          Except from the class that bridges the gap between the GUI (QML) and C++, is it a mandatory to code only with classes?

          J Offline
          J Offline
          JonB
          wrote on 20 Jun 2022, 08:35 last edited by
          #4

          @Mick_1
          Your list of classes is not unreasonable, at least initially. Over time you may want to divide these down into multiple classes and/or add other classes.

          It does not matter that classes can be re-used several times, but your examples may not be and will only be instantiated once. That is OK, it does not obviate the benefits of writing classes or mean you should not do so because you will only have one object of that class.

          There are too may advantages to using classes to list them all. What is your alternative? To have every function free/global? To dream up naming conventions to prevent similar names clashing?

          Yes, classes may have to expose public methods for the outside world to access. Make public just what needs to be public, make private/protected what does not. Judicious architectural design of your program should mean you do not have too many public attributes. If you find every class is accessing loads of things in every other class you may have a design which could be improved. Using Qt's signals and slots can help in keeping classes quite separate and not needing to know about each directly.

          1 Reply Last reply
          2
          • M Offline
            M Offline
            Mick_1
            wrote on 20 Jun 2022, 09:06 last edited by
            #5

            Thanks for your feedback.

            I'm happy with what I've done so far, I think I've coded some pretty clean stuff respecting the few points you listed in your post.

            I'm an embedded programmer and so I'm mostly used to code in C and so in procedural. That's why sometimes I feel like I'm not doing it right and I'd like to go back to procedural even in C++.

            I understand, I'm going to train with the object-oriented philosophy, I like it anyway, but I wanted to know if it's not a received idea to code necessarily in OOP when using C++.

            J 1 Reply Last reply 20 Jun 2022, 09:18
            0
            • M Mick_1
              20 Jun 2022, 09:06

              Thanks for your feedback.

              I'm happy with what I've done so far, I think I've coded some pretty clean stuff respecting the few points you listed in your post.

              I'm an embedded programmer and so I'm mostly used to code in C and so in procedural. That's why sometimes I feel like I'm not doing it right and I'd like to go back to procedural even in C++.

              I understand, I'm going to train with the object-oriented philosophy, I like it anyway, but I wanted to know if it's not a received idea to code necessarily in OOP when using C++.

              J Offline
              J Offline
              JonB
              wrote on 20 Jun 2022, 09:18 last edited by JonB
              #6

              @Mick_1
              Well, C++ is just a superset of C so you do not have to to do any OOP if you really don't want to --- except e.g. where the outside world demands you do so, by passing objects around.

              Give C++ a go. It does not take long to realise that the ability to compartmentalise into classes is an improvement over plain C. BTW, if it helps any, class in C++ is technically the same thing as/based on/extended from struct in C. Objects are just structs, with a bunch of member variables and functions defined inside them.

              1 Reply Last reply
              2

              1/6

              16 Jun 2022, 13:02

              • Login

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