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. Problem with function that could be only global or static and displaying contents
Forum Update on Monday, May 27th 2025

Problem with function that could be only global or static and displaying contents

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 2.4k 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.
  • N Offline
    N Offline
    never_ever
    wrote on 12 Jan 2015, 09:54 last edited by
    #1

    Hi,
    I have a function that could be only global or I can do it static if I use it in class. The problem is that I want to know what happens in that function while it is working or even if it is complete (users should see what happens in it, it is not only for me). Is there any possibility to check it?
    Thanks,

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 12 Jan 2015, 09:59 last edited by
      #2

      Hi,
      Sorry, it's not real clear what you need, but let me guess.
      You want feedback to the user what happens in a function?
      How do you need the feedback? If used in a GUI element, simple create a class, setup the signal to send text and connect your GUI element to it to display it. If you want the feedback when debugging, use the qDebug() so it's displayed in the output pane.
      Or when that's not your thing, use the cout from the STL and run your program in the console.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • N Offline
        N Offline
        never_ever
        wrote on 12 Jan 2015, 10:18 last edited by
        #3

        The problem is that I use GUI where I have some buttons and one of them indicate function that is static. I want to show to user what happens in that function while it is working and I want to know when it finishes. I have to show to user when it finishes because only then he could continue work with program.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ckakman
          wrote on 12 Jan 2015, 19:24 last edited by
          #4

          Hi,

          If you want to update the UI while a function is executing, you can call "processEvents()":http://doc.qt.io/qt-5/qcoreapplication.html#processEvents. A better way to use that function is to pass in some flags:
          @
          qApp->processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers );
          @

          "qApp":http://doc.qt.io/qt-5/qapplication.html#qApp is a macro to QApplication or QCoreApplication depending on the type of application.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 12 Jan 2015, 21:33 last edited by
            #5

            Hi,

            What kind of feedback do you want to give to your user ? Something like a QProgressBar ?

            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
            • N Offline
              N Offline
              never_ever
              wrote on 15 Jan 2015, 11:54 last edited by
              #6

              Inside that function I do few things. There is:

              • progress of function executing
              • information that data was saved to the file (and I want to show to user name of saved file)
              • information that function ends executing

              Firstly, when I started to do this program I also wanted to disable button that is responsible for further executing my program until my function is done. But with static function I can't use signals and I don't know how to do this in other way.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ckakman
                wrote on 15 Jan 2015, 15:44 last edited by
                #7

                You can use QMetaObject::invokeMethod() to call a slot.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  never_ever
                  wrote on 15 Jan 2015, 17:35 last edited by
                  #8

                  It could be great idea, I check if it works in my program, thanks.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 15 Jan 2015, 21:57 last edited by
                    #9

                    @ ckakman call a slot from a static function ? Do you mean the slot of the QProgressBar ?

                    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
                    • C Offline
                      C Offline
                      ckakman
                      wrote on 16 Jan 2015, 15:50 last edited by
                      #10

                      [quote author="SGaist" date="1421359077"]@ ckakman call a slot from a static function ? Do you mean the slot of the QProgressBar ?[/quote]

                      If s/he passes a QObject-derived object's pointer a static function and doesn't feel disturbed by such a hack, why not?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 17 Jan 2015, 00:44 last edited by
                        #11

                        Threading issues mostly (not that threading was mentioned)

                        Out of curiosity why is it mandatory that this function be static or global ?

                        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
                        • N Offline
                          N Offline
                          never_ever
                          wrote on 17 Jan 2015, 18:17 last edited by
                          #12

                          I use a library that need pointer to function, so I can't write my function as a method of my class, because then I get
                          "argument of type void(MyClass::)() is incompatible with parameter of type void()()"
                          so the only solution was writing this function as global or static.

                          1 Reply Last reply
                          0

                          1/12

                          12 Jan 2015, 09:54

                          • Login

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