Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt Application Fails to Load QML Modules in Docker Container
Servers for Qt installer are currently down

Qt Application Fails to Load QML Modules in Docker Container

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
6 Posts 2 Posters 533 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rakesh U
    wrote on 13 Sept 2024, 09:00 last edited by
    #1

    Hello Qt Community,

    I’m encountering several issues while running a Qt QML application inside a Docker container. The application starts but fails to load QML modules and the required Qt platform plugin. I’m looking for guidance on how to resolve these issues.
    Issue Description
    When running my Qt QML application in a Docker container, I get the following errors:

    Application starting...
    qt.qpa.xcb: could not connect to display :0
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    
    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
    
    

    Dockerfile Configuration
    Here’s the Dockerfile I’m using to build the Docker image:

    # Use an Ubuntu base image
    FROM ubuntu:22.04
    
    # Install required dependencies
    RUN apt-get update && \
        apt-get install -y \
        build-essential \
        cmake \
        qtbase5-dev \
        qtdeclarative5-dev \
        qtquickcontrols2-5-dev \
        libgl1-mesa-dev \
        libxcb1 \
        libxcb-xinerama0 \
        libxcb-xkb1 \
        libxkbcommon-x11-0 \
        libxkbcommon0 \
        libgl1-mesa-glx \
        libgl1-mesa-dri \
        && rm -rf /var/lib/apt/lists/*
    
    # Set environment variables for Qt
    ENV QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms
    
    # Create an application directory
    WORKDIR /usr/src/app
    
    # Copy your Qt QML application to the container
    COPY . /usr/src/app
    
    # Build the QML application using CMake
    RUN mkdir build && cd build && cmake .. && make
    
    # Command to run the QML application
    CMD ["./build/Qml_App"]
    
    

    CPP main

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
        qDebug() << "Application starting...";
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        qDebug() << "Loading QML file from" << url.toString();
        QObject::connect(
            &engine,
            &QQmlApplicationEngine::objectCreated,
            &app,
            [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl) {
                    qDebug() << "Failed to load QML file";
                    QCoreApplication::exit(-1);
                }
            },
            Qt::QueuedConnection);
        engine.load(url);
    
        qDebug() << "Application loaded";
        return app.exec();
    }
    
    

    Troubleshooting Steps Taken

    • Verified Installation of Qt Modules: Ensured the Dockerfile installs all necessary Qt packages.

    • Checked Qt Plugin Path: Set QT_QPA_PLATFORM_PLUGIN_PATH in the Dockerfile.

    • Verified QML Imports: Confirmed that the QML modules should be present in the container.

    • Verified Plugin Path: Ensured the Qt platform plugin path is correctly set.

    Request for Assistance

    • Ensuring the required QML modules are correctly installed in the Docker container.

    • Why Window is not opening(QML)

    • Diagnosing why the Qt platform plugin "xcb" cannot be initialized.

    Thank you in advance for your help!

    Best regards,
    Rakesh U

    J 1 Reply Last reply 13 Sept 2024, 09:09
    0
    • R Rakesh U
      13 Sept 2024, 09:00

      Hello Qt Community,

      I’m encountering several issues while running a Qt QML application inside a Docker container. The application starts but fails to load QML modules and the required Qt platform plugin. I’m looking for guidance on how to resolve these issues.
      Issue Description
      When running my Qt QML application in a Docker container, I get the following errors:

      Application starting...
      qt.qpa.xcb: could not connect to display :0
      qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
      This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
      
      Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
      
      

      Dockerfile Configuration
      Here’s the Dockerfile I’m using to build the Docker image:

      # Use an Ubuntu base image
      FROM ubuntu:22.04
      
      # Install required dependencies
      RUN apt-get update && \
          apt-get install -y \
          build-essential \
          cmake \
          qtbase5-dev \
          qtdeclarative5-dev \
          qtquickcontrols2-5-dev \
          libgl1-mesa-dev \
          libxcb1 \
          libxcb-xinerama0 \
          libxcb-xkb1 \
          libxkbcommon-x11-0 \
          libxkbcommon0 \
          libgl1-mesa-glx \
          libgl1-mesa-dri \
          && rm -rf /var/lib/apt/lists/*
      
      # Set environment variables for Qt
      ENV QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms
      
      # Create an application directory
      WORKDIR /usr/src/app
      
      # Copy your Qt QML application to the container
      COPY . /usr/src/app
      
      # Build the QML application using CMake
      RUN mkdir build && cd build && cmake .. && make
      
      # Command to run the QML application
      CMD ["./build/Qml_App"]
      
      

      CPP main

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
      #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      #endif
          qDebug() << "Application starting...";
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          qDebug() << "Loading QML file from" << url.toString();
          QObject::connect(
              &engine,
              &QQmlApplicationEngine::objectCreated,
              &app,
              [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl) {
                      qDebug() << "Failed to load QML file";
                      QCoreApplication::exit(-1);
                  }
              },
              Qt::QueuedConnection);
          engine.load(url);
      
          qDebug() << "Application loaded";
          return app.exec();
      }
      
      

      Troubleshooting Steps Taken

      • Verified Installation of Qt Modules: Ensured the Dockerfile installs all necessary Qt packages.

      • Checked Qt Plugin Path: Set QT_QPA_PLATFORM_PLUGIN_PATH in the Dockerfile.

      • Verified QML Imports: Confirmed that the QML modules should be present in the container.

      • Verified Plugin Path: Ensured the Qt platform plugin path is correctly set.

      Request for Assistance

      • Ensuring the required QML modules are correctly installed in the Docker container.

      • Why Window is not opening(QML)

      • Diagnosing why the Qt platform plugin "xcb" cannot be initialized.

      Thank you in advance for your help!

      Best regards,
      Rakesh U

      J Offline
      J Offline
      JonB
      wrote on 13 Sept 2024, 09:09 last edited by JonB
      #2

      @Rakesh-U said in Qt Application Fails to Load QML Modules in Docker Container:

      qt.qpa.xcb: could not connect to display :0

      This is the only message which matters. However you invoke your application with the Docker Container you do not have an Xorg display available to it. Are you running an X server? Try to run some other Xorg application, such as xterm, and you should be seeing the same error.

      R 1 Reply Last reply 13 Sept 2024, 11:16
      1
      • R Offline
        R Offline
        Rakesh U
        wrote on 13 Sept 2024, 09:11 last edited by
        #3

        running on ubuntu 20.04

        J 1 Reply Last reply 13 Sept 2024, 09:12
        0
        • R Rakesh U
          13 Sept 2024, 09:11

          running on ubuntu 20.04

          J Offline
          J Offline
          JonB
          wrote on 13 Sept 2024, 09:12 last edited by
          #4

          @Rakesh-U said in Qt Application Fails to Load QML Modules in Docker Container:

          running on ubuntu 20.04

          Whatever, it's still as per my answer above.

          1 Reply Last reply
          1
          • J JonB
            13 Sept 2024, 09:09

            @Rakesh-U said in Qt Application Fails to Load QML Modules in Docker Container:

            qt.qpa.xcb: could not connect to display :0

            This is the only message which matters. However you invoke your application with the Docker Container you do not have an Xorg display available to it. Are you running an X server? Try to run some other Xorg application, such as xterm, and you should be seeing the same error.

            R Offline
            R Offline
            Rakesh U
            wrote on 13 Sept 2024, 11:16 last edited by
            #5

            @JonB still getting same error

            J 1 Reply Last reply 13 Sept 2024, 13:11
            0
            • R Rakesh U
              13 Sept 2024, 11:16

              @JonB still getting same error

              J Offline
              J Offline
              JonB
              wrote on 13 Sept 2024, 13:11 last edited by
              #6

              @Rakesh-U Did you/could you try running xterm in exactly same environment?

              1 Reply Last reply
              1

              1/6

              13 Sept 2024, 09:00

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved