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



  • 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,



  • 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.



  • 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.



  • 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.


  • Lifetime Qt Champion

    Hi,

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



  • 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.



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



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


  • Lifetime Qt Champion

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



  • [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?


  • Lifetime Qt Champion

    Threading issues mostly (not that threading was mentioned)

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.