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. QUser class wanted
Forum Updated to NodeBB v4.3 + New Features

QUser class wanted

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 6 Posters 7.9k Views 5 Watching
  • 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.
  • SGaistS SGaist

    Hi,

    Do you mean something like kdesudo ?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #5

    @SGaist said in QUser class wanted:

    Hi,

    Do you mean something like kdesudo ?

    No, no, nothing like sudo! I just want to retrieve the current user information --- such as his name --- on Linux/Windows/MacWhatever. But by it making whatever native OS calls, not using environment variables which can be set to anything.

    Like @Wieland was indicating, I suspect that means calling get(e)uid un Linux, GetWindowsUsername or some-such under 'doze, etc. Then providing whatever info is common back to the class.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #6

      @JNBarchan said in QUser class wanted:

      I suspect that means calling get(e)uid un Linux, GetWindowsUsername or some-such under 'doze, etc. Then providing whatever info is common back to the class.

      Yes.

      JonBJ 1 Reply Last reply
      0
      • ? A Former User

        @JNBarchan said in QUser class wanted:

        I suspect that means calling get(e)uid un Linux, GetWindowsUsername or some-such under 'doze, etc. Then providing whatever info is common back to the class.

        Yes.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #7

        @Wieland said in QUser class wanted:

        @JNBarchan said in QUser class wanted:

        I suspect that means calling get(e)uid un Linux, GetWindowsUsername or some-such under 'doze, etc. Then providing whatever info is common back to the class.

        Yes.

        Yes, as in: yes, that's what's needed but there isn't presently something I can use which does this? Sorry, I'm not certain, I can't use the POSIX thing under Windows, or can I?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #8

          AFAIK there is nothing like that "QUser" readily available. So I think you have to build your own one. For this you'd have to write platform specific code for POSIX, Windows, and all the other systems you need to support. There are a couple of ways how to implement that in actual code. In its simplest form it would look like:

          QString JNB::getUserName()
          {
              QString userName;
          
          #ifdef Q_OS_LINUX
              // call linux API, like getuid()
          #endif
          
          #ifdef Q_OS_WIN32
              // call Windows API
          #endif
          
              return userName;
          }
          
          JonBJ 1 Reply Last reply
          0
          • ? A Former User

            AFAIK there is nothing like that "QUser" readily available. So I think you have to build your own one. For this you'd have to write platform specific code for POSIX, Windows, and all the other systems you need to support. There are a couple of ways how to implement that in actual code. In its simplest form it would look like:

            QString JNB::getUserName()
            {
                QString userName;
            
            #ifdef Q_OS_LINUX
                // call linux API, like getuid()
            #endif
            
            #ifdef Q_OS_WIN32
                // call Windows API
            #endif
            
                return userName;
            }
            
            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #9

            @Wieland
            OIC, yes. My prob is that I'm Python/PyQt, I could do that in 10 seconds in C++ :)
            That's why I'd like Qt to kindly provide just this in their cross-platform library. Please!

            kshegunovK 1 Reply Last reply
            0
            • JonBJ JonB

              @Wieland
              OIC, yes. My prob is that I'm Python/PyQt, I could do that in 10 seconds in C++ :)
              That's why I'd like Qt to kindly provide just this in their cross-platform library. Please!

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #10

              Can't you create your code in C++ and just provide bindings for python (like PyQt does)? That's what I'd attempt. :)

              Read and abide by the Qt Code of Conduct

              JonBJ ? 2 Replies Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #11

                Oh, okay. Python already has some built-in stuff for you, Miscellaneous operating system interfaces.

                JonBJ 1 Reply Last reply
                1
                • kshegunovK kshegunov

                  Can't you create your code in C++ and just provide bindings for python (like PyQt does)? That's what I'd attempt. :)

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #12

                  @kshegunov
                  I share the code with others. We don't write extra bits in C++, compile them cross-platform, share the code... We use Python. Think as: these guys don't use C++. That's why Qt5 + PyQt5 is just marvellous for x-platform. It provides loads of other things (files, windows, ...) x-plat, I'd like it to provide user info.
                  :)

                  1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    Can't you create your code in C++ and just provide bindings for python (like PyQt does)? That's what I'd attempt. :)

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #13

                    @kshegunov said in QUser class wanted:

                    Can't you create your code in C++ and just provide bindings

                    Ever done that? No fun at all...

                    JonBJ kshegunovK 2 Replies Last reply
                    1
                    • ? A Former User

                      @kshegunov said in QUser class wanted:

                      Can't you create your code in C++ and just provide bindings

                      Ever done that? No fun at all...

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #14

                      @Wieland said in QUser class wanted:

                      @kshegunov said in QUser class wanted:

                      Can't you create your code in C++ and just provide bindings

                      Ever done that? No fun at all...

                      Yeah, thanks for that observation. I haven't tried, but it sounds alarm bells...

                      1 Reply Last reply
                      0
                      • Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by Chris Kawa
                        #15

                        I'm afraid there's too much of a divergence on what a "user" means on different platforms to enclose it in such class. I'm no Linux programmer, but on Windows at least you've got your currently logged in user, the user that the application is run with (might not be the same at all), the user that owns a particular thread, elevation, and then there's client impersonation mechanism... I doubt that these concepts map easily to other platforms so that they could be captured under a simple QUser umbrella.

                        JonBJ 1 Reply Last reply
                        1
                        • ? A Former User

                          @kshegunov said in QUser class wanted:

                          Can't you create your code in C++ and just provide bindings

                          Ever done that? No fun at all...

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #16

                          @Wieland said in QUser class wanted:

                          @kshegunov said in QUser class wanted:

                          Can't you create your code in C++ and just provide bindings

                          Ever done that? No fun at all...

                          Nope, that's why I phrased it as a question.

                          Read and abide by the Qt Code of Conduct

                          1 Reply Last reply
                          0
                          • Chris KawaC Chris Kawa

                            I'm afraid there's too much of a divergence on what a "user" means on different platforms to enclose it in such class. I'm no Linux programmer, but on Windows at least you've got your currently logged in user, the user that the application is run with (might not be the same at all), the user that owns a particular thread, elevation, and then there's client impersonation mechanism... I doubt that these concepts map easily to other platforms so that they could be captured under a simple QUser umbrella.

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #17

                            @Chris-Kawa said in QUser class wanted:

                            I'm afraid there's too much of a divergence on what a "user" means on different platforms to enclose it in such class. I'm no Linux programmer, but on Windows at least you've got your currently logged in user, the user that the application is run with (might not be the same at all), the user that owns a particular thread, elevation, and then there's client impersonation mechanism... I doubt that these concepts map easily to other platforms so that they could be captured under a simple QUser umbrella.

                            All of them provide a user name, for example. Which happens to be what I need. Actually, client impersonation/elevation maps quite well to Linux real versus effective uid. If you take, say, the POSIX abstraction it does find common ground with useful information. It was just a hope that Qt might help me :)

                            kshegunovK 1 Reply Last reply
                            0
                            • ? A Former User

                              Oh, okay. Python already has some built-in stuff for you, Miscellaneous operating system interfaces.

                              JonBJ Online
                              JonBJ Online
                              JonB
                              wrote on last edited by
                              #18

                              @Wieland said in QUser class wanted:

                              Oh, okay. Python already has some built-in stuff for you, Miscellaneous operating system interfaces.

                              I'm afraid that's why I quoted https://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python. The point is nobody found a layer which did work x-plat.

                              1 Reply Last reply
                              0
                              • JonBJ JonB

                                @Chris-Kawa said in QUser class wanted:

                                I'm afraid there's too much of a divergence on what a "user" means on different platforms to enclose it in such class. I'm no Linux programmer, but on Windows at least you've got your currently logged in user, the user that the application is run with (might not be the same at all), the user that owns a particular thread, elevation, and then there's client impersonation mechanism... I doubt that these concepts map easily to other platforms so that they could be captured under a simple QUser umbrella.

                                All of them provide a user name, for example. Which happens to be what I need. Actually, client impersonation/elevation maps quite well to Linux real versus effective uid. If you take, say, the POSIX abstraction it does find common ground with useful information. It was just a hope that Qt might help me :)

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by
                                #19

                                @JNBarchan said in QUser class wanted:

                                All of them provide a user name, for example. Which happens to be what I need.

                                Mind me asking what for, as this is rather odd requirement?

                                Read and abide by the Qt Code of Conduct

                                JonBJ 1 Reply Last reply
                                0
                                • kshegunovK kshegunov

                                  @JNBarchan said in QUser class wanted:

                                  All of them provide a user name, for example. Which happens to be what I need.

                                  Mind me asking what for, as this is rather odd requirement?

                                  JonBJ Online
                                  JonBJ Online
                                  JonB
                                  wrote on last edited by JonB
                                  #20

                                  @kshegunov said in QUser class wanted:

                                  @JNBarchan said in QUser class wanted:

                                  All of them provide a user name, for example. Which happens to be what I need.

                                  Mind me asking what for, as this is rather odd requirement?

                                  Wow, I think it's a not uncommon requirement! Of course I don't mind you asking.

                                  I would like to affect my Qt application's UI depending on who the end user is, in whatever fashion. So I need to identify the user, username would be fine.

                                  My targets may be Windows or Linux, users might be a single user on own PC or member of team logged onto a network. Obviously I know the information about the user varies across these, I'll take whatever I'm given.

                                  I don't like the idea of retrieving that information through environmental variables a user can simply set. @Wieland's code looks like a good start, but it's inconvenient for me to have to do that via C++, so I'd like friendly Qt to kindly offer that as a x-platform utility function (which the next release of PyQt will pick up and make available to me) :)

                                  kshegunovK jsulmJ 2 Replies Last reply
                                  0
                                  • JonBJ JonB

                                    @kshegunov said in QUser class wanted:

                                    @JNBarchan said in QUser class wanted:

                                    All of them provide a user name, for example. Which happens to be what I need.

                                    Mind me asking what for, as this is rather odd requirement?

                                    Wow, I think it's a not uncommon requirement! Of course I don't mind you asking.

                                    I would like to affect my Qt application's UI depending on who the end user is, in whatever fashion. So I need to identify the user, username would be fine.

                                    My targets may be Windows or Linux, users might be a single user on own PC or member of team logged onto a network. Obviously I know the information about the user varies across these, I'll take whatever I'm given.

                                    I don't like the idea of retrieving that information through environmental variables a user can simply set. @Wieland's code looks like a good start, but it's inconvenient for me to have to do that via C++, so I'd like friendly Qt to kindly offer that as a x-platform utility function (which the next release of PyQt will pick up and make available to me) :)

                                    kshegunovK Offline
                                    kshegunovK Offline
                                    kshegunov
                                    Moderators
                                    wrote on last edited by kshegunov
                                    #21

                                    @JNBarchan said in QUser class wanted:

                                    Wow, I think it's a not uncommon requirement! Of course I don't mind you asking.

                                    Some people do and I have never needed it, so I'd qualified it as uncommon in my mind. ;)

                                    My targets may be Windows or Linux, users might be a single user on own PC or member of team logged onto a network. Obviously I know the information about the user varies across these, I'll take whatever I'm given.

                                    If python allows you to directly call the system you could try whoami which supposedly should work on both windows and linux. If you don't have system (or akin) in python, alternatively you could use QProcess to invoke the command line interpreter and run it. See for example:

                                    https://technet.microsoft.com/en-us/library/cc771299(v=ws.11).aspx
                                    http://www.linfo.org/whoami.html

                                    I can't tell you how it retrieves that information though, so it may very well depend on the environment variables as well.

                                    Read and abide by the Qt Code of Conduct

                                    JonBJ 1 Reply Last reply
                                    1
                                    • kshegunovK kshegunov

                                      @JNBarchan said in QUser class wanted:

                                      Wow, I think it's a not uncommon requirement! Of course I don't mind you asking.

                                      Some people do and I have never needed it, so I'd qualified it as uncommon in my mind. ;)

                                      My targets may be Windows or Linux, users might be a single user on own PC or member of team logged onto a network. Obviously I know the information about the user varies across these, I'll take whatever I'm given.

                                      If python allows you to directly call the system you could try whoami which supposedly should work on both windows and linux. If you don't have system (or akin) in python, alternatively you could use QProcess to invoke the command line interpreter and run it. See for example:

                                      https://technet.microsoft.com/en-us/library/cc771299(v=ws.11).aspx
                                      http://www.linfo.org/whoami.html

                                      I can't tell you how it retrieves that information though, so it may very well depend on the environment variables as well.

                                      JonBJ Online
                                      JonBJ Online
                                      JonB
                                      wrote on last edited by
                                      #22

                                      @kshegunov said in QUser class wanted:

                                      If python allows you to directly call the system you could try whoami which supposedly should work on both windows and linux. If you don't have system (or akin) in python, alternatively you could use QProcess to invoke the command line interpreter and run it.

                                      Thanks, but I'd rather use environment variables than run an OS command!! I'll look through the python os module and find some calls which give me the best from what's there, I think.

                                      kshegunovK 1 Reply Last reply
                                      1
                                      • JonBJ JonB

                                        @kshegunov said in QUser class wanted:

                                        If python allows you to directly call the system you could try whoami which supposedly should work on both windows and linux. If you don't have system (or akin) in python, alternatively you could use QProcess to invoke the command line interpreter and run it.

                                        Thanks, but I'd rather use environment variables than run an OS command!! I'll look through the python os module and find some calls which give me the best from what's there, I think.

                                        kshegunovK Offline
                                        kshegunovK Offline
                                        kshegunov
                                        Moderators
                                        wrote on last edited by
                                        #23

                                        The last option is to write the C++ class, write a proposal in the bug tracker where you say why you need this and where it should go, provide testing and documentation for that code and have it included in Qt. Then wait (or appeal to the devs) for it to get python binding.
                                        It's not exactly a very quick process, but if you think it's needed we would all appreciate your effort. :)

                                        Read and abide by the Qt Code of Conduct

                                        JonBJ 1 Reply Last reply
                                        1
                                        • kshegunovK kshegunov

                                          The last option is to write the C++ class, write a proposal in the bug tracker where you say why you need this and where it should go, provide testing and documentation for that code and have it included in Qt. Then wait (or appeal to the devs) for it to get python binding.
                                          It's not exactly a very quick process, but if you think it's needed we would all appreciate your effort. :)

                                          JonBJ Online
                                          JonBJ Online
                                          JonB
                                          wrote on last edited by
                                          #24

                                          @kshegunov
                                          Did I mention I kinda want to start using this on Monday...? ;-)

                                          Yep, point taken. I have only just gotten involved in Qt, and Python. Thanks for suggestions.

                                          1 Reply Last reply
                                          1

                                          • Login

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