微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

虽然包含 <X11/extensions/scrnsaver.h> 显示错误

如何解决虽然包含 <X11/extensions/scrnsaver.h> 显示错误

当我在 Qt 中包含 时,它会向我显示错误

    /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)

我正在尝试检索用户空闲时间

尝试链接 this linkthis link,但对我不起作用

我的个人资料

#-------------------------------------------------
#
# 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

主窗口.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();
}

我的项目是创建一个用户监控应用程序,如果用户在固定时间内不使用键盘鼠标,则必须停止应用程序的某些部分。我成功地为 Windows 和 MacO 创建了它。 我用

为linux平台创建了它

#define MOUSEFILE "/dev/input/event4"

#define MOUSEMOVEFILE "/dev/input/js1"

#define KEYBOARDFILE "/dev/input/event0"

以上方法。此方法在树莓派操作系统-桌面版中成功运行,但在ubantu中失败。 所以这就是为什么我在“方法中进行试验

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。