Results 1 to 9 of 9

Thread: Keboardlayout

  1. #1
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Smile Keboardlayout

    Hi,
    In lineedit, I like to force it type in Farsi(Persian, which it is activated in windows xp). I can do that in vb by using
    GetKeyboardLayout(0) to 67699721
    then ActivateKeyboardLayout(0) .How can I do it in Qt, please help.
    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Keboardlayout

    Qt is C++, you can use any winapi function, just include "windows.h" and use ActivateKeyboardLayout

  3. #3
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keboardlayout

    Thanks a lot; Any examples or link,hint over Internet in this regard?
    Thanks again

  4. #4
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keboardlayout

    There is HKL type conversion issue
    Qt Code:
    1. t=GetKeyboardLayout(0)
    2. if t=67699721
    3. t=Activat...
    To copy to clipboard, switch view to plain text mode 
    What should be before t for declaring (int, QString or QVariant are not acceptable), sorry for the .... question
    please help
    thanks

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Keboardlayout

    Declare it to be of type HKL, which should be included as a result of including windows.h.

  6. #6
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keboardlayout

    I did but then I cannot write :
    Qt Code:
    1. if (t=67699721)
    To copy to clipboard, switch view to plain text mode 
    the compiler give me error of wrong conversion I tried :
    Qt Code:
    1. int t= GetKeyboardLayout(0)->i;
    2. if (t=67699721)
    3. t=ActivateKeyboardLayout(0,0)->i;
    To copy to clipboard, switch view to plain text mode 
    the compiler does not complain but it does not type correct Persian; it types cobination of Persian with some
    other languages; I appriciate your help, a lot

  7. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Keboardlayout

    Qt Code:
    1. if (t=67699721)
    To copy to clipboard, switch view to plain text mode 
    If you are new to C / C++, above line is assignment, not equality test. It sets 't' to have value 67699721, and returns that value. If you want compare values, use 't==other_value'.

    According to documentation, there is a method named LoadKeyboardLayout. It expects a "language identifier string", take a look at this list, you can find there id of Persian locale to be 0x0429, so according to this:
    For example, U.S. English has a language identifier of 0x0409, so the primary U.S. English layout is named "00000409".
    you should try somethig like:
    Qt Code:
    1. LoadKeyboardLayout(L"00000429",KLF_ACTIVATE); //!< im not sure about the L ...
    To copy to clipboard, switch view to plain text mode 
    Finally, check the output of this method and use GetLastError to know details if something will go wrong.

    Please note that I haven't tried the above code, I'm just guessing how this should look like according to microsoft docs.

    -------
    edit: I'm not sure about the KLF_ACTIVATE flag either, maybe you'll need to try with other values (described in first link in this post)
    Last edited by stampede; 17th February 2011 at 22:42.

  8. #8
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keboardlayout

    Thanks, I will.

  9. #9
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keboardlayout

    Solved, Thanks a lot.
    should use == instead of= and the code is 404226304

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.