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 8.2k 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.
  • 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 Offline
      JonBJ Offline
      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 Offline
          JonBJ Offline
          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
          • 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) :)

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #25

            @JNBarchan said in QUser class wanted:

            I would like to affect my Qt application's UI depending on who the end user is

            Why do you need user name for that? Isn't it just user configuration stored in user home directory (UNIX/LINUX) or user part of the registry on Windows? For that you can use QSettings.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            0
            • jsulmJ jsulm

              @JNBarchan said in QUser class wanted:

              I would like to affect my Qt application's UI depending on who the end user is

              Why do you need user name for that? Isn't it just user configuration stored in user home directory (UNIX/LINUX) or user part of the registry on Windows? For that you can use QSettings.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #26

              @jsulm said in QUser class wanted:

              @JNBarchan said in QUser class wanted:

              I would like to affect my Qt application's UI depending on who the end user is

              Why do you need user name for that? Isn't it just user configuration stored in user home directory (UNIX/LINUX) or user part of the registry on Windows? For that you can use QSettings.

              That works where the UI alterations are purely controlled by a user's own "preferences". However, not when the rules are imposed by the system/Administrator, and are not to be overridden by some user's fancy. For example, some areas of the system are only to be accessible to "administrators" and not to "plain users". I don't want some end user to go editing his own file/registry to switch on things he should not have access to!

              Doubtless in practice this will be implemented by assigning "roles" to users for the checks, rather than directly on the username. But I need to know the name securely to determine the correct role(s). Role membership may be implemented via the application having a database table of "username+role", or possibly via native Linux/Windows "group" membership, if I can determine that similarly securely (again, QUser class could have included group membership cross-platform just like username, as it is I would have to write that myself with the same problems as for username).

              Additionally, I may wish to log the user's name in log files from the application or from MySQL. Again, I want the secure, correct user's name, not what he might fancy poking into a settings.ini file/registry, environment variable or similar!

              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