0

When i including <X11/extensions/scrnsaver.h> in Qt it shows me the error

    /usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:63: error: expected identifier before numeric constant
         None = 0,                               // invalid event
         ^~~~

/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:63: error: expected ‘}’ before numeric constant
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:63: error: expected unqualified-id before numeric constant
         None = 0,                               // invalid event
         ^~~~

/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘friend’ used outside of class
     Q_ENUM(Type)
     ^~~~~~
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘constexpr const QMetaObject* const qt_getEnumMetaObject’ redeclared as different kind of symbol
     Q_ENUM(Type)
     ^~~~~~
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘Type’ was not declared in this scope
     Q_ENUM(Type)
     ^~~~~~
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘friend’ used outside of class
     Q_ENUM(Type)
     ^~~~~~
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘constexpr const char* const qt_getEnumName’ redeclared as different kind of symbol
     Q_ENUM(Type)
     ^~~~~~
/usr/include/i386-linux-gnu/qt5/QtCore/qcoreevent.h:295: error: ‘Type’ was not declared in this scope
     Q_ENUM(Type)

I am trying to retrieve the user idle time

tried the links this link and this link but it is not working for me

My profile

#-------------------------------------------------
#
# Project created by QtCreator 2021-05-01T07:53:43
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

LIBS += -lX11
TARGET = GlobalHook
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QDebug>
#include <X11/extensions/scrnsaver.h>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    void StartLoop();
    QTimer * timer;
    ~MainWindow();

private slots:
    void on_btnStart_clicked();

    void on_btnStop_clicked();

private:
    Ui::MainWindow *ui;
    Display * m_Display;
    int m_EventBase,m_ErrorBase;
    XScreenSaverInfo  m_Info;
    uint m_MSec;
};

#endif // MAINWINDOW_H

MainWindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    timer=new QTimer(this);
    connect(timer,&QTimer::timeout,this,QOverload<>::of(&MainWindow::StartLoop));
}

void MainWindow::StartLoop()
{
    if(XScreenSaverQueryExtension(m_Display,&m_EventBase,&m_ErrorBase))
    {
        XScreenSaverQueryInfo(m_Display,DefaultRootWindow(m_Display),&m_Info);
        m_MSec=(uint)m_Info.idle;
        qDebug()<<"idle time"<<m_MSec;

    }

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnStart_clicked()
{
    timer->start(1000);
}

void MainWindow::on_btnStop_clicked()
{
    timer->stop();
}

My project is to create a user monitoring application, if the user is not using keyboard mouse for a fixed time ,some part of application have to be stopped. I created it for windows and MacOs successfully. I created it for linux platform with

#define MOUSEFILE "/dev/input/event4"

#define MOUSEMOVEFILE "/dev/input/js1"

#define KEYBOARDFILE "/dev/input/event0"

above method. This method is working in RaspberryPi OS -Desktop version successfully,But it fails in ubantu. So thats why i am giving a trial in "<X11/extensions/scrnsaver.h>" method

Arun K
  • 413
  • 4
  • 15

0 Answers0