Below I have described the method to get active (focused) windows title using Qt in Linux systems (Such as Ubuntu, CentOS etc.) Basically you use xdotool with two parameters mentioned below to get the title of current window which has the focus.
Parameter 1 needs to be getwindowfocus and param 2 should be getwindowname. See below:
QString MyClass::getTopWindowTitleLinux()
{
QProcess process(this);
process.setProgram("xdotool");
process.setArguments(QStringList() << "getwindowfocus" << "getwindowname");
process.start();
while (process.state() != QProcess::NotRunning)
qApp->processEvents();
return process.readAll();
}
Updated June 22, 2016
You might need to install xdotool if it doesn’t exist.