The following program executed in my host KDE Neon machine (up to date upgraded to 18.04) outputs Hello World! 1
as expected while it outputs Hello World! 0
when executed from a Docker container built using the Dockerfile below and running with sudo docker run -it qdir
.
Does QDir need dbus or another service running ?
C++ program:
#include <QDir>
#include <iostream>
int main(int argc [[maybe_unused]], char** argv [[maybe_unused]])
{
QDir d("/");
std::cout << "Hello World! " << d.exists() << std::endl;
return 0;
}
Dockerfile:
FROM kdeneon/plasma:user-lts
USER root
RUN apt-get install -y qt5-default
WORKDIR /
COPY qdir /
CMD /bin/bash
Edit, CMakeLists.txt to build the program:
project(qdir)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.3.0")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core)
include_directories(${Qt5Core_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
set(qdir_SRCS main.cpp)
add_executable(qdir ${qdir_SRCS})
target_link_libraries(qdir ${Qt5Core_LIBRARIES})
install(TARGETS qdir RUNTIME DESTINATION bin)
Edit2: I created a github project regrouping all of the above. To reproduce the problem, if you have the Qt SDK, cmake, ninja and docker, just do:
git clone https://github.com/kleag/qdirtest
cd qdirtest
./test.sh
This is the output I get:
$ ./test.sh
[…]
Successfully built f710cbb7a3c9
Successfully tagged qdir:latest
Hello World! 1
Hello World! 0
I got the answer from apachelogger on KDE forums: