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. QMediaPlayer does not work on NixOS

QMediaPlayer does not work on NixOS

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
10 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    Volker Weissmann
    wrote on last edited by
    #1

    I tried building a video player like this:
    example.pro:

    QT      += core gui widgets multimedia multimediawidgets
    
    CONFIG  += c++17
    
    SOURCES += main.cpp 
    

    main.cpp:

    #include <QApplication>                                                                                                                                                                                             
    #include <QWidget>                                                                                                                                                                                                  
    #include <QPushButton>                                                                                                                                                                                              
    #include <QVBoxLayout>                                                                                                                                                                                              
    #include <QMediaPlayer>                                                                                                                                                                                             
    #include <QVideoWidget>                                                                                                                                                                                             
    #include <QUrl>                                                                                                                                                                                                     
                                                                                                                                                                                                                        
    int main(int argc, char *argv[]) {                                                                                                                                                                                  
        QApplication app(argc, argv);                                                                                                                                                                                   
                                                                                                                                                                                                                        
        QWidget window;                                                                                                                                                                                                 
        window.resize(640, 480);                                                                                                                                                                                        
                                                                                                                                                                                                                        
        QVideoWidget *videoWidget = new QVideoWidget;                                                                                                                                                                   
        QMediaPlayer *player = new QMediaPlayer;                                                                                                                                                                        
                                                                                                                                                                                                                        
        player->setVideoOutput(videoWidget);                                                                                                                                                                            
        //player->setMedia(QUrl::fromLocalFile("/home/user/Downloads/sample-5s.mp4")); // also works                                                                                                                    
        player->setMedia(QUrl("https://file-examples.com/storage/feaa6a7f0468517af9bc02d/2017/04/file_example_MP4_480_1_5MG.mp4"));                                                                                     
                                                                                                                                                                                                                        
        QVBoxLayout *layout = new QVBoxLayout;                                                                                                                                                                          
        layout->addWidget(videoWidget);                                                                                                                                                                                 
                                                                                                                                                                                                                        
        window.setLayout(layout);                                                                                                                                                                                       
        window.show();                                                                                                                                                                                                  
        player->play();                                                                                                                                                                                                 
                                                                                                                                                                                                                        
        return app.exec();                                                                                                                                                                                              
    }                                                                                                                                                                                                                   
    

    If I build and run this under ArchLinux with the packages qt5-base and qt5-multimedia installed, it works fine (except for a segmentation fault on exit, but that is a different topic). If however, I build and run this in nixos with nix-shell -p qt5Full libsForQt5.qt5.qtmultimedia I get an empty window, with nothing in stdout or stderr. If I run it with QT_DEBUG_PLUGINS=1 I cannot spot anything suspicious in the output.

    Any idea how to make progress here? Is that a bug in the nixos package of Qt?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Which exact version of Qt are you using ?
      Which window manager are running with ?
      Which desktop environment are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Volker Weissmann
        wrote on last edited by
        #3

        Hello SGaist,

        Im using QtVersion: 5.15.16 and sway (a wayland compositor).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          And for the desktop environment ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          0
          • SGaistS SGaist

            And for the desktop environment ?

            V Offline
            V Offline
            Volker Weissmann
            wrote on last edited by
            #5

            @SGaist said in QMediaPlayer does not work on NixOS:

            And for the desktop environment ?

            Sway. Nothing else.

            I installed it like this:

            programs.sway = {
                enable = true;
                wrapperFeatures.gtk = true;
              };
            
            1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              run
              strace your_app
              you may be able to find some clues

              V 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                run
                strace your_app
                you may be able to find some clues

                V Offline
                V Offline
                Volker Weissmann
                wrote on last edited by
                #7

                @JoeCFD said in QMediaPlayer does not work on NixOS:

                run
                strace your_app
                you may be able to find some clues

                Just did that.

                Here is the result:
                https://weissmann.pm/2025-qt5-nixos-bug-strace.txt

                1 Reply Last reply
                0
                • JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  openat(AT_FDCWD, "/home/unpriv/.Xdefaults-nichts", O_RDONLY) = -1 ENOENT (No such file or directory)

                  <====X11 Fallback Attempts. Are your env settings correct for Wayland? Not familiar with your OS.

                  1 Reply Last reply
                  0
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #9
                    setenv( "DISPLAY",         ":0",      1 );
                    setenv( "GDK_BACKEND",     "wayland", 1 );
                    setenv( "QT_QPA_PLATFORM", "wayland", 1 );
                    
                    setenv( "XDG_RUNTIME_DIR", "/run/user/1000",            1 );
                    setenv( "WAYLAND_DISPLAY", "wayland-1",                 1 );
                    setenv( "QT_QPA_FONTDIR",  "/usr/share/fonts/truetype", 1 ); 
                    

                    I need these settings in my Qt code on Yocto wayland .

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Volker Weissmann
                      wrote on last edited by
                      #10

                      Xeyes shows that the application is using X11.
                      Once I'll find time, I try to force it to use Wayland.

                      1 Reply Last reply
                      0

                      • Login

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