April 14, 2011

pooja1650 pooja1650
Lab Rat
5 posts

How to lock/ unlock Windows PC using Qt pro-gramatically?

 

Hi,

I need to lock/ unlock PC (Windows O/S) with Qt pro-grammatically. Is their any direct API/ functions available for this? Any possible way to do this?

8 replies

April 14, 2011

Andre Andre
Robot Herder
6296 posts

There is no Qt API for that. Look into the windows API’s to see if you can find anything platform specific.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 14, 2011

pooja1650 pooja1650
Lab Rat
5 posts

Yes, I checked that and found the way to lock the PC. Now if I make an .exe which can lock the PC, then how can I launch that .exe from Qt application on some event?

April 14, 2011

Andre Andre
Robot Herder
6296 posts

You can use the native API directly from your Qt application. Qt apps are just C++, and you can use native API just fine. No need for a separate application, your app just won’t be portable to other platforms such a Linux and Mac if you do this, but given the task, I guess that is not an issue for you. If you want to interact with external applications, you can look into QProcess though.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 14, 2011

pooja1650 pooja1650
Lab Rat
5 posts

well, i found the link http://msdn.microsoft.com/en-us/library/aa376869(v=vs.85).aspx to lock the PC using VC++/ C#. So, you want to say that this code can be directly used in Qt?

April 14, 2011

Andre Andre
Robot Herder
6296 posts

Basically, yes. I would not put it in a main(), and I am not sure what the #pragma is supposed to do, but otherwise it should work like this.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 14, 2011

pooja1650 pooja1650
Lab Rat
5 posts

Ok. Thanks a lot for your quick responses.

I will try this code, not in main(), but on some particular event occurrence.

I also don’t know how #pragma comment will behave in this case.

April 14, 2011

Volker Volker
Ant Farmer
5428 posts

To cite MSDN at http://msdn.microsoft.com/en-us/library/7f0aews7(VS.80).aspx

The comment-type is one of the predefined identifiers, described below, that specifies the type of comment record. The optional commentstring is a string literal that provides additional information for some comment types. Because commentstring is a string literal, it obeys all the rules for string literals with respect to escape characters, embedded quotation marks (”), and concatenation.
lib
Places a library-search record in the object file. This comment type must be accompanied by a commentstring parameter containing the name (and possibly the path) of the library that you want the linker to search. The library name follows the default library-search records in the object file; the linker searches for this library just as if you had named it on the command line provided that the library is not specified with /nodefaultlib. You can place multiple library-search records in the same source file; each record appears in the object file in the same order in which it is encountered in the source file.
If the order of the default library and an added library is important, compiling with the /Zl switch will prevent the default library name from being placed in the object module. A second comment pragma then can be used to insert the name of the default library after the added library. The libraries listed with these pragmas will appear in the object module in the same order they are found in the source code.

So it should be sufficient to add to your .pro:

  1. LIBS += user32.lib
  2. // or
  3. LIBS += -luser32

April 14, 2011

pooja1650 pooja1650
Lab Rat
5 posts

Thanks…

I will try that soon.

 
  ‹‹ [Solved]How to change font color of QListWidgetItem when it is in edit mode      Adding bullet points to a QTextEdit? ››

You must log in to post a reply. Not a member yet? Register here!