Screen locker in Qt

强颜欢笑 提交于 2019-12-14 02:35:03

问题


Are there any Qt based screen lockers on linux systems ?

i.e. 4 pin digit or password screen locker ?

Any reference will be greatly appreciated.


回答1:


On linux, the screen locking is done by the screensavers, and the password is the one from the user linux account.

You can use QProcess to run a command line and check if it was successful:

  • gnome-screensaver-command --lock
  • xscreensaver-command --lock
  • qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
  • qdbus org.gnome.ScreenSaver /ScreenSaver Lock
  • xlock

And/or use QtDBus module to do the same thing

// Tries to lock the screen and returns true if successful 
bool LockScreenWithDBus() {
    QDBusConnection bus = QDBusConnection::sessionBus();
    if(!bus.isConnected())
        return false;

    QStringList services;       
    services << "org.freedesktop.ScreenSaver"             
             << "org.gnome.ScreenSaver"
    // These last two are probably not necessary, because kde uses freedesktop
    // conventions for dbus
             << "org.kde.ScreenSaver"
             << "org.kde.krunner";           

    foreach(QString service, services) {        
        QDBusInterface screenSaverInterface(service, "/ScreenSaver",
                                            QString(), bus);
        if (!screenSaverInterface.isValid())
            continue;       
        QDBusReply<void> reply = screenSaverInterface.call("Lock");
        if (reply.isValid())
            return true;
    }
    return false;
}



回答2:


You can create a top level FrameLess Semi transparent QWidget of Screen Height and screen width and in its center place your Textbox for password asking.



来源:https://stackoverflow.com/questions/7120055/screen-locker-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!