问题
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