Skip to content

Instantly share code, notes, and snippets.

@tobiasBora
Last active May 25, 2023 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasBora/6f114cca1affb5528c872ca01d7e28c1 to your computer and use it in GitHub Desktop.
Save tobiasBora/6f114cca1affb5528c872ca01d7e28c1 to your computer and use it in GitHub Desktop.

Demonstration of QML with Qt5 + qmake + nix

If you have nix installed compile and run with:

$ nix build
$ ./result/bin/demo 

Explaination: we load the .qml file with qrc:///main.qml: it uses for that the file qml.qrc (the name is not important) that lists the resource files. This 'qml.qrc file is then given to RESOURCES in demo.pro in order to compile the resources and include them in the final binary.

SOURCES += main.cpp
TEMPLATE = app
RESOURCES += qml.qrc
QT += qml
TARGET = demo
isEmpty(PREFIX) {
PREFIX = /usr/local
}
# install the binary
target.path = $$PREFIX/bin
INSTALLS += target
{ lib
, stdenv
, qmake
, qt5
, wrapQtAppsHook
}:
stdenv.mkDerivation rec {
pname = "";
version = "";
src = ./.;
nativeBuildInputs = [ qmake wrapQtAppsHook ];
buildInputs = [
qt5.full
];
}
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1668650906,
"narHash": "sha256-JuiYfDO23O8oxUUOmhQflmOoJovyC5G4RjcYQMQjrRE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3a86856a13c88c8c64ea32082a851fefc79aa700",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
{
description = "A very basic flake";
outputs = { self, nixpkgs }: let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
packages.x86_64-linux.default = pkgs.libsForQt5.callPackage ./derivation_demo.nix {};
};
}
//https://riptutorial.com/qml/example/14475/creating-a-qtquick-window-from-cplusplus
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
import QtQuick 2.5
import QtQuick.Window 2.2
Window { // Must be this type to be loaded by QQmlApplicationEngine.
visible: true
title: qsTr("Hello World")
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
@quantenzitrone
Copy link

im getting this error:

libGL error: MESA-LOADER: failed to open iris: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_2.36' not found (required by /nix/store/98sq0hkrbda37k9iayqdqchkibp8530y-llvm-15.0.7-lib/lib/libLLVM-15.so) (search paths /run/opengl-driver/lib/dri, suffix _dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open iris: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_2.36' not found (required by /nix/store/98sq0hkrbda37k9iayqdqchkibp8530y-llvm-15.0.7-lib/lib/libLLVM-15.so) (search paths /run/opengl-driver/lib/dri, suffix _dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open swrast: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_2.36' not found (required by /nix/store/98sq0hkrbda37k9iayqdqchkibp8530y-llvm-15.0.7-lib/lib/libLLVM-15.so) (search paths /run/opengl-driver/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
QGLXContext: Failed to create dummy context
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
fish: Job 1, 'result/bin/demo' terminated by signal SIGABRT (Abort)

do you know whats going on?
i already tried switching to nixpkgs/release-22.11 and changing the qt version to the newer qt6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment