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. How to lock/ unlock Windows PC using Qt pro-gramatically?

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.7k 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.
  • P Offline
    P Offline
    pooja1650
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pooja1650
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pooja1650
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pooja1650
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

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

                  bq. 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:

                  @
                  LIBS += user32.lib
                  // or
                  LIBS += -luser32
                  @

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pooja1650
                    wrote on last edited by
                    #9

                    Thanks...

                    I will try that soon.

                    1 Reply Last reply
                    0

                    • Login

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