Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Image disply without window

QML Image disply without window

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 5 Posters 652 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    Ok Im new to qml and I found this example code to run:

    import QtQuick 2.12
    
    Image {
        id: root
        source: "images/background.png"
    }
    

    However If I run this nothing shows up.

    I created an empty Qt Quick app with creator and it looks like it needs a window.

    So this worked well:

    import QtQuick 2.14
    import QtQuick.Window 2.14
    
    Window {
        visible: true
        width: 640
        height: 480
    
        Image {
            id: root
            source: "images/background.png"
        }
    }
    

    So short stupid question. Can Image get displayed without the window?

    1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      How do you execute that code?

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sandro4912
        wrote on last edited by
        #3

        I just made a empty Qt Quick project and hit build and run in debug.

        I think the qml gets run with its coresponding main.cpp

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        
        int main(int argc, char *argv[])
        {
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        
            QGuiApplication app(argc, argv);
        
            QQmlApplicationEngine engine;
            const QUrl url(QStringLiteral("qrc:/main.qml"));
            QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                             &app, [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            }, Qt::QueuedConnection);
            engine.load(url);
        
            return app.exec();
        }
        
        1 Reply Last reply
        0
        • MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • S Offline
            S Offline
            sandro4912
            wrote on last edited by
            #5

            @sandro4912 said in QML Image disply without window:

            import QtQuick 2.12

            Image {
            id: root
            source: "images/background.png"
            }

            That was not the question.

            The Question is. Can this work without window like this:

            import QtQuick 2.12
            
            Image {
                id: root
                source: "images/background.png"
            }
            
            J.HilkJ 1 Reply Last reply
            0
            • S sandro4912

              @sandro4912 said in QML Image disply without window:

              import QtQuick 2.12

              Image {
              id: root
              source: "images/background.png"
              }

              That was not the question.

              The Question is. Can this work without window like this:

              import QtQuick 2.12
              
              Image {
                  id: root
                  source: "images/background.png"
              }
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @sandro4912
              AFAIK QQmlApplicationEngine needs a Window or similar top level QML component

              if you use a QQuickWidget / QQuickView you may get away with an Item/Image as root element


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • S Offline
                S Offline
                sandro4912
                wrote on last edited by
                #7

                @J-Hilk said in QML Image disply without window:

                QQuickWidget

                I modified my main to this:

                #include <QApplication>
                #include <QQuickWidget>
                
                int main(int argc, char *argv[])
                {
                    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                
                    QApplication app(argc, argv);
                
                    auto view = new QQuickWidget;
                    view->setSource(QStringLiteral("qrc:/main.qml"));
                    view->show();
                
                    return app.exec();
                }
                

                Now I wonder whats the difference between QQuickWidget and QQmlApplicationEngine. Why not do everything with the QQuickWidget?

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

                  Hi,

                  Because you might want to only use QML. QQuickWidget adds the widget module as dependency which might not be what you want.

                  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
                  3

                  • Login

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