开发者

Macro detect KDE or GNOME in qt4

开发者 https://www.devze.com 2023-01-17 04:28 出处:网络
I have a problem to detect when used in GNOME or KDE operating sys开发者_运维知识库tem that runs the application.

I have a problem to detect when used in GNOME or KDE operating sys开发者_运维知识库tem that runs the application. The program I am doing QT4, and I have trouble feeling of look- in the systray, so I pass it to KDE, but which is not macro to do so. PD: I use KDE and C / C. I search in web and I see this: Creating executable for Windows using Qt on Linux But for KDE?

Greetings Alejandro Espinosa


Qt does not provide this kind of defines based on the desktop environment. If you need to know the desktop environment at compilation time, then your best bet would be to modify your build system to pass the necessary defines to the compiler. The desktop environment can be concluded by different prerequisites such as environment variables, availability of applications, libraries or headers. The choice depends on what you're trying to do.

For instance, if you take the environment inspection route, KDE defines the KDE_FULL_SESSION variable whereas GNOME has the DESKTOP_SESSION variable set to "gnome". FYI, that's how Qt detects the DE at run time.


you can do it with help of bash by writing a script containing the given code

#!/bin/bash
echo $XDG_CURRENT_DESKTOP

Now when you execute the code from Qprocess you can read the output of Qprocess and check what is the output of Qprocess.

{
QProcess chkdesk;
chkdesk.start("getenv");  //getenv is bash script 
qDebug() << chkdesk.readAll();  
}
0

精彩评论

暂无评论...
验证码 换一张
取 消