Install qt and qt touch screen calibration tslib under linux

Install qt under linux

在 Linux 系统下安装 Qt,可以通过以下步骤进行操作:

1. 下载 Qt 安装包:首先,你需要从 Qt 官方网站(https://www.qt.io/)下载适用于 Linux 的 Qt 安装包。选择与你的系统和需求相匹配的版本(例如 Qt 5.x 或 Qt 6.x),以及所需的组件。

2. 安装依赖项:在开始安装 Qt 之前,你需要确保系统已经安装了一些必要的依赖项。这些依赖项可能因发行版而异,一般包括编译工具链(如 gcc、g++)、CMake、OpenGL 相关库、X11 开发库等。你可以使用系统的包管理器来安装这些依赖项。

3. 运行安装程序:将下载的 Qt 安装包解压缩后,进入解压后的目录,并找到名为 "qt-installer" 或类似的可执行文件。然后,在终端中切换到该目录,并运行安装程序。你可以使用以下命令:

   ```shell
   ./qt-installer
  1. Select installation options: After the installer starts, follow the prompts. You can choose the installation path, install components, personalize settings, etc.

  2. Start the installation: After confirming the installation options, click the "Install" button to start installing Qt. This process may take some time, depending on the components you choose and system capabilities.

  3. Configure Qt: After the installation is complete, open a terminal and enter the Qt installation directory (by default, it is under $HOME/Qtthe directory). Run ./MaintenanceToolthe command to manage and configure the installed Qt. For example, you can add or remove components, update Qt version, etc.

  4. Configure environment variables: In order to use Qt normally, you need to add the execution path of Qt to the system's PATH environment variable. You can edit the ~/.bashrcor ~/.profilefile and add the following:

    export PATH=$PATH:<Qt_installation_directory>/Qt_version/bin
    

    where <Qt_installation_directory>is your Qt installation path and <Qt_version>is your Qt version number.

  5. Verify installation: Enter the following command in the terminal to verify whether Qt is installed successfully:

    qmake --version
    

    If the Qt version information is displayed correctly, the installation is successful.

Please note that the above steps only apply to Qt installation packages downloaded through the official website. If you are using the package manager that comes with your distribution, it may be different. In addition, depending on your needs and system configuration, other operations and settings may be required, such as setting up the compilation tool chain, adding plug-ins, etc. It is recommended to refer to the Qt official documentation and installation guide during the installation process for more detailed information and guidance.

qt touch screen calibration tslib

在 QT 中,要进行触摸屏校准,可以使用 tslib 库来实现。以下是一些基本步骤:

1. 安装 tslib 库:首先,确保 tslib 库已经正确安装在你的系统中。你可以通过包管理器来安装它,比如使用以下命令在 Ubuntu 上安装 tslib:

   ```shell
   sudo apt-get install tslib
  1. Configure tslib: Add the relevant configuration of tslib in the .pro file of the QT project. For example, you could add the following to your .pro file:

    # 引入 tslib 相关头文件和库
    INCLUDEPATH += /usr/include/tslib
    LIBS += -L/usr/lib -lts
    
  2. Create a touch screen calibration class: Create a class for touch screen calibration in the QT project. You can call this class TouchscreenCalibration.

  3. Implement touch screen calibration function: In the TouchscreenCalibration class, you can use the functions provided by tslib to perform touch screen calibration. For example, in calibrate()the function, you can use ts_calibrate()the function to perform calibration operations and obtain the calibration results.

    #include <tslib.h>
    
    void TouchscreenCalibration::calibrate()
    {
          
          
        struct tsdev *ts;
        struct ts_sample sample[3];
    
        // 打开触摸屏设备
        ts = ts_open("/dev/input/eventX", 0);
        if (!ts) {
          
          
            qDebug() << "Failed to open touchscreen device";
            return;
        }
    
        // 设置校准参数
        ts_setup(ts);
    
        // 执行触摸屏校准
        if (ts_calibrate(ts, sample, false) < 0) {
          
          
            qDebug() << "Touchscreen calibration failed";
        } else {
          
          
            // 获取校准结果
            struct ts_sample results[3];
            ts_get_calib(ts, results);
            // 处理校准结果,例如保存到配置文件中
            // ...
        }
    
        // 关闭触摸屏设备
        ts_close(ts);
    }
    
  4. Call the touch screen calibration function: Call the function of the TouchscreenCalibration class at the appropriate location in your QT project calibrate()to perform touch screen calibration.

Please note that the above code is a simple example and may need to be modified and adapted according to your specific needs when used in practice. Also, please make sure that the touch screen device has been mounted correctly and the tslib library has been installed correctly before performing touch screen calibration.

Guess you like

Origin blog.csdn.net/m0_46376834/article/details/132732893