Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Path to image in xcassets folder (iOS)
QtWS25 Last Chance

Path to image in xcassets folder (iOS)

Scheduled Pinned Locked Moved Solved Mobile and Embedded
iosxcodeassets
4 Posts 2 Posters 3.7k 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.
  • J Offline
    J Offline
    JRohner
    wrote on 18 May 2016, 21:22 last edited by JRohner
    #1

    Hi!

    Hope you can help me with this... I have a large number of images that i want to use in an iOS app. Adding them to a .qrc does not work ("xcode build failed"), so i made a .xcassets file in xcode to which I want to add images. However, no images are shown when running on an iPhone (but it does work in the simulator). I followed the advice here.

    How do i find the correct path to my images?

    Thanks in advance!

    My .pro file:

    QT       += core gui multimediawidgets
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = AssetsTest
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    ios {
        assets_catalogs.files = $$files($$PWD/*.xcassets)
        QMAKE_BUNDLE_DATA += assets_catalogs
    }
    

    And my .cpp file:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QPixmap pixmap("//Users/JCROHNER/Programmering/QT Projekt/AssetsTest/Media.xcassets/Photo 2014-05-10 11 33 08.imageset/Photo 2014-05-10 11 33 08.jpg");
        ui->label->setPixmap(pixmap);
    
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 May 2016, 22:58 last edited by
      #2

      Hi,

      You hardcoded the path to your image on your computer so it won't be valid at all on your device. You should rather use QCoreApplication::applicationDirPath and move to the right folder from there.

      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
      1
      • J Offline
        J Offline
        JRohner
        wrote on 19 May 2016, 08:45 last edited by
        #3

        Tanks a lot! Your suggestion solved my problem.
        /JC

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JRohner
          wrote on 19 May 2016, 08:45 last edited by
          #4

          Here is the code that works:

              QString path = QCoreApplication::applicationDirPath() + "/Photo 2014-05-10 11 33 08.jpg";
              QPixmap pixmap(path);
              ui->label->setPixmap(pixmap);
          
          1 Reply Last reply
          0

          1/4

          18 May 2016, 21:22

          • Login

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