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. Question About Calculator Example
Qt 6.11 is out! See what's new in the release blog

Question About Calculator Example

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 3.2k Views 1 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
    DragonOsman
    wrote on last edited by
    #3

    It's derived from QToolButton. Deriving from it gives the error conversion to inaccessible base class "QToolButton" is not allowed., though. The other error is gone now. I #included QtWidgets/qtoolbutton.h, by the way.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      You should derive public from QToolButton, not private.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • D Offline
        D Offline
        DragonOsman
        wrote on last edited by
        #5

        That fixed it. I don't know why I did it, but I just put class Button : QToolButton. But yeah, thanks for now.

        I still need to know how to use that Qt Tools for VS extension, but I'll get to that after the code is all written.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DragonOsman
          wrote on last edited by
          #6

          What about my question on switching from raw pointers to smart pointers in the app's code? Should I just use std::unique_ptr throughout the whole thing? Once again for reference, it's this example. My reasoning is that I want to follow the RAII principle. Raw pointers don't follow it.

          jsulmJ 1 Reply Last reply
          0
          • D DragonOsman

            What about my question on switching from raw pointers to smart pointers in the app's code? Should I just use std::unique_ptr throughout the whole thing? Once again for reference, it's this example. My reasoning is that I want to follow the RAII principle. Raw pointers don't follow it.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @DragonOsman For QObject derived classes you should not use smart pointers as you will get double deletes. Simply set parent in such objects and the parent will delete its children. See https://doc.qt.io/archives/qt-4.8/objecttrees.html

            https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              So you mean I just need to pass a smart pointer as the argument to the parent parameter in the constructor? And are all of the classes I'm using derived from QObject?

              Also, how do I change the colors of widgets? Along with that, I also think I'll add some more buttons if it won't ruin the grid layout. I want to add parentheses (two buttons here), a function to raise to nth power, and a function to take the nth root. I know the latter two are unary functions, but what category would the parenthesis buttons fall under?

              jsulmJ JonBJ 2 Replies Last reply
              0
              • D DragonOsman

                So you mean I just need to pass a smart pointer as the argument to the parent parameter in the constructor? And are all of the classes I'm using derived from QObject?

                Also, how do I change the colors of widgets? Along with that, I also think I'll add some more buttons if it won't ruin the grid layout. I want to add parentheses (two buttons here), a function to raise to nth power, and a function to take the nth root. I know the latter two are unary functions, but what category would the parenthesis buttons fall under?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @DragonOsman said in Question About Calculator Example:

                pass a smart pointer as the argument to the parent

                No! RAW pointer.

                "how do I change the colors of widgets?" - see https://doc.qt.io/qt-5/stylesheet-syntax.html

                "but what category would the parenthesis buttons fall under?" - I don't understand this question. A button is a button, doesn't matter what action it triggers.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • D DragonOsman

                  So you mean I just need to pass a smart pointer as the argument to the parent parameter in the constructor? And are all of the classes I'm using derived from QObject?

                  Also, how do I change the colors of widgets? Along with that, I also think I'll add some more buttons if it won't ruin the grid layout. I want to add parentheses (two buttons here), a function to raise to nth power, and a function to take the nth root. I know the latter two are unary functions, but what category would the parenthesis buttons fall under?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #10

                  @DragonOsman
                  Some classify parentheses in a category of their own, e.g. https://chortle.ccsu.edu/java5/Notes/chap09B/ch09B_2.html

                  An expression is a combination of literals, operators, variable names, and parentheses used to calculate a value.

                  https://softwareengineering.stackexchange.com/questions/208350/what-do-you-call-parentheses-operators is worth a read through. there the accepted answer states "grouping operators" for your case:

                  Parentheses ("(" and ")") are operators when used in an expression like a*(b+c), in which case they're often referred to as grouping operators.

                  The other answer describes "parentheses operators" as punctuators.

                  So take your pick :)

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    DragonOsman
                    wrote on last edited by
                    #11

                    Thanks for the reply.

                    I tried to build the project in VS2019 using the Qt VS2019 Tools, but the build failed due to MSBuild errors. I hope someone on here can help me, though I may have to consult the MSDN forums too since it's about MSBuild. Gist link.

                    I tried to build it with VS2019 normally before this as well and it failed due to linker errors. If you want me to, I could try that again. But please tell me what .lib files to link against please. Thanks.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DragonOsman
                      wrote on last edited by
                      #12

                      I was able to build the example in Qt Creator. I'm going to try extending it from here. I want to try making it into a scientific calculator, but I need some help.

                      You know how there's this call to tr() in the example code? tr("x\302\262"). I want to know how to do this to get the "x to the power of (any given) n" symbol.

                      Also, when implementing the functions for parentheses, do I just write code to append parentheses?

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mpergand
                        wrote on last edited by mpergand
                        #13

                        @DragonOsman said in Question About Calculator Example:

                        "x\302\262" x²

                        You can use the caret (^) as exponentiation operator.

                        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