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. Return QMessageBox::Icon instead of bool to check if method worked fine
Forum Updated to NodeBB v4.3 + New Features

Return QMessageBox::Icon instead of bool to check if method worked fine

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 421 Views 2 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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    My question is about preventing errors that users can make.
    Usually we write:

    QDir dir("example");
    if (!dir.exists()) {
        QMessageBox::critical(nullptr, "Error", "Cannot find the example directory");
        return false;
    }
    

    But is it ok to return QMessageBox::Icon like in the following code? Or maybe nobody does like this and this is bad form?

    QDir dir("example");
    if (!dir.exists()) {
        QMessageBox::critical(nullptr, "Error", "Cannot find the example directory");
        return QMessageBox::Icon::Critical;
    }
    
    JonBJ 1 Reply Last reply
    0
    • Please_Help_me_DP Please_Help_me_D

      @JonB thank you for commenting
      I'm in doubt, I don't know exactly what I want.
      bool has two states and QMessageBox::Icon has few of them. Probably in future I will process not only QMessageBox::Icon::Critical but also QMessageBox::Icon::Warning I don't know
      But I feel it is a strange output...

      I don't have enough experience to cath errors so I'm experimenting

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

      @Please_Help_me_D
      Hi
      Why not defines your own enum and return one of these to tell the caller what happened.
      So it matches what you are really doing.

      enum FileSelectStatus{ ExampleDirNotFound , DirIsEmpty, InvalidX, AllOK };

      Or what else can go wrong.

      Please_Help_me_DP 1 Reply Last reply
      2
      • Please_Help_me_DP Please_Help_me_D

        Hi,

        My question is about preventing errors that users can make.
        Usually we write:

        QDir dir("example");
        if (!dir.exists()) {
            QMessageBox::critical(nullptr, "Error", "Cannot find the example directory");
            return false;
        }
        

        But is it ok to return QMessageBox::Icon like in the following code? Or maybe nobody does like this and this is bad form?

        QDir dir("example");
        if (!dir.exists()) {
            QMessageBox::critical(nullptr, "Error", "Cannot find the example directory");
            return QMessageBox::Icon::Critical;
        }
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Please_Help_me_D said in Return QMessageBox::Icon instead of bool to check if method worked fine:

        But is it ok to return QMessageBox::Icon like in the following code?

        It's a free world (just). Yes, you can do that. Depends on the function's return type.

        Or maybe nobody does like this and this is bad form?

        It would be a very odd choice for function return type; bool false would be usual. Why would you want to return this?

        Please_Help_me_DP 1 Reply Last reply
        4
        • JonBJ JonB

          @Please_Help_me_D said in Return QMessageBox::Icon instead of bool to check if method worked fine:

          But is it ok to return QMessageBox::Icon like in the following code?

          It's a free world (just). Yes, you can do that. Depends on the function's return type.

          Or maybe nobody does like this and this is bad form?

          It would be a very odd choice for function return type; bool false would be usual. Why would you want to return this?

          Please_Help_me_DP Offline
          Please_Help_me_DP Offline
          Please_Help_me_D
          wrote on last edited by
          #3

          @JonB thank you for commenting
          I'm in doubt, I don't know exactly what I want.
          bool has two states and QMessageBox::Icon has few of them. Probably in future I will process not only QMessageBox::Icon::Critical but also QMessageBox::Icon::Warning I don't know
          But I feel it is a strange output...

          I don't have enough experience to cath errors so I'm experimenting

          mrjjM 1 Reply Last reply
          0
          • Please_Help_me_DP Please_Help_me_D

            @JonB thank you for commenting
            I'm in doubt, I don't know exactly what I want.
            bool has two states and QMessageBox::Icon has few of them. Probably in future I will process not only QMessageBox::Icon::Critical but also QMessageBox::Icon::Warning I don't know
            But I feel it is a strange output...

            I don't have enough experience to cath errors so I'm experimenting

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

            @Please_Help_me_D
            Hi
            Why not defines your own enum and return one of these to tell the caller what happened.
            So it matches what you are really doing.

            enum FileSelectStatus{ ExampleDirNotFound , DirIsEmpty, InvalidX, AllOK };

            Or what else can go wrong.

            Please_Help_me_DP 1 Reply Last reply
            2
            • mrjjM mrjj

              @Please_Help_me_D
              Hi
              Why not defines your own enum and return one of these to tell the caller what happened.
              So it matches what you are really doing.

              enum FileSelectStatus{ ExampleDirNotFound , DirIsEmpty, InvalidX, AllOK };

              Or what else can go wrong.

              Please_Help_me_DP Offline
              Please_Help_me_DP Offline
              Please_Help_me_D
              wrote on last edited by
              #5

              @mrjj thank you
              Maybe I will create something like QMessageBox (or inherit from it) with the opportunity to retrieve enum from appeared window (warning or critical or something else)

              mrjjM 1 Reply Last reply
              0
              • Please_Help_me_DP Please_Help_me_D

                @mrjj thank you
                Maybe I will create something like QMessageBox (or inherit from it) with the opportunity to retrieve enum from appeared window (warning or critical or something else)

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

                @Please_Help_me_D
                Hi
                It would be easier just to put in a function that returns your enum and then use that instead of
                QMessageBox directly.

                1 Reply Last reply
                1

                • Login

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