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

import images directory ?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.4k Views 2 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.
  • mehmetakM Offline
    mehmetakM Offline
    mehmetak
    wrote on last edited by
    #1

    hi everyone ,

    i cant load image from images directory. How can use currentdir in qml

    main.cpp code is

    <code>
    qmlRegisterType<Object>("org.yeni.example", 1, 0, "Object");
    qmlRegisterType<Getsqlmodel>("org.qtproject.examples.calendar1", 1, 0, "Getsqlmodel");

    QQmlApplicationEngine engine;
    
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    

    </code>

    p3c0P 1 Reply Last reply
    0
    • mehmetakM mehmetak

      hi everyone ,

      i cant load image from images directory. How can use currentdir in qml

      main.cpp code is

      <code>
      qmlRegisterType<Object>("org.yeni.example", 1, 0, "Object");
      qmlRegisterType<Getsqlmodel>("org.qtproject.examples.calendar1", 1, 0, "Getsqlmodel");

      QQmlApplicationEngine engine;
      
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      

      </code>

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @mehmetak
      Where is this images directory ? If it is in same directory where main.qml is present then you can access images from it using the relative path. Something like:

      //main.qml
      ...
      source: "images/someimage.png"
      

      157

      1 Reply Last reply
      0
      • mehmetakM Offline
        mehmetakM Offline
        mehmetak
        wrote on last edited by
        #3

        i solved problem with c++ integration .

        Object.cpp

        QString Object::deneme(QString dd) {

        QDir ss ;
        return ss.absolutePath()+'/'+dd;
        

        }

        main.cpp

        qmlRegisterType<Object>("org.yeni.example", 1, 0, "Object");
        qmlRegisterType<Getsqlmodel>("org.qtproject.examples.calendar1", 1, 0, "Getsqlmodel");

        main.qml

        import org.qtproject.examples.calendar1 1.0
        import org.yeni.example 1.0

        ...................
        ..................
        Object {
        id:getir
        }

        Getsqlmodel {
        id:sqlQ
        }

        Image {
        id:rocket
        // source:'http://play.brokt.com/~fritzy/rocket.png'
        source:'file:' + getir.deneme('debug/rocket.png')
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        }

        p3c0P 1 Reply Last reply
        0
        • mehmetakM mehmetak

          i solved problem with c++ integration .

          Object.cpp

          QString Object::deneme(QString dd) {

          QDir ss ;
          return ss.absolutePath()+'/'+dd;
          

          }

          main.cpp

          qmlRegisterType<Object>("org.yeni.example", 1, 0, "Object");
          qmlRegisterType<Getsqlmodel>("org.qtproject.examples.calendar1", 1, 0, "Getsqlmodel");

          main.qml

          import org.qtproject.examples.calendar1 1.0
          import org.yeni.example 1.0

          ...................
          ..................
          Object {
          id:getir
          }

          Getsqlmodel {
          id:sqlQ
          }

          Image {
          id:rocket
          // source:'http://play.brokt.com/~fritzy/rocket.png'
          source:'file:' + getir.deneme('debug/rocket.png')
          anchors.horizontalCenter: parent.horizontalCenter
          anchors.verticalCenter: parent.verticalCenter
          }

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @mehmetak Ok. That's great. But I think it should be accessible by relative path too.

          157

          1 Reply Last reply
          0
          • mehmetakM Offline
            mehmetakM Offline
            mehmetak
            wrote on last edited by
            #5

            @p3c0 thx p3c0 . i liked c++ integration.

            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