Qt World Summit: Register Today!

How can i use WMI in Qt? cant get msdn sample to work properly in qt5.2

  • I am trying to test an msdn sample on WMI notification in c++ which is located here: "Example: Receiving Event Notifications Through WMI ":http://msdn.microsoft.com/en-us/library/aa390425(v=vs.85).aspx in a Qt5.2 project.
    Everything compiles just fine and runs well, But when I try to run the sample code, I get stuck at the very beginning!
    I get the error:

    bq. Failed to initialize COM library. Error code = 0xffffffff80010106

    I\ve read somewhere that it seems Qt itself initializes the com objects, So there is no need to re initialize it.
    In that case if i comment the initialization part i get *CoInitializeSecurity * failure error.!
    What am i missing here?
    I even tried running those codes inside another thread like :
    @ std::thread t(&frmProcess::WMIMethod2,this);
    where WMIMethod2 contains the code for executing wmi stuff as shown in the link provided above form msdn.
    If i do this i get this error :
    !http://i43.tinypic.com/289dlrr.jpg(Qt5.2 error )!
    What is wrong here and how can i solve this ?

  • Lifetime Qt Champion


    AFAIK, when using com objects, you still need to do the initialization yourself. And it seems (but I might be wrong) that you are trying to access GUI element from another thread which is not supported.

    I would rather try to encapsulate the WMI notifier in a QObject maybe move it to it's own thread if needed and emit signals from it to update the GUI

    Hope it helps

  • Thanks, Would it be possible for you to show me a small example of doing such a thing?

Log in to reply