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
Forum Updated to NodeBB v4.3 + New Features

Qt Application Fails to Load QML Modules in Docker Container

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
6 Posts 2 Posters 686 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 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

    JonBJ 1 Reply Last reply
    0
    • R Rakesh U

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      1
      • R Offline
        R Offline
        Rakesh U
        wrote on last edited by
        #3

        running on ubuntu 20.04

        JonBJ 1 Reply Last reply
        0
        • R Rakesh U

          running on ubuntu 20.04

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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
          • JonBJ JonB

            @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 last edited by
            #5

            @JonB still getting same error

            JonBJ 1 Reply Last reply
            0
            • R Rakesh U

              @JonB still getting same error

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

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

              1 Reply Last reply
              1

              • Login

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