Dynamic Path QFile



  • Hi!
    I'm doing a function in which a program selects a picture from a file using a variable given by a String for example

    QString name = "carlos" + ".png";
    // (the first part of the string is given by a QLineEdit introduced by the user)
    QFile File("/home/pics/name")
    

    Thanks in advance.


  • Qt Champions 2016

    what is the question?

    QString name = "carlos" + ".png";
    QFile File("/home/pics/" + name");

    or

    QFile File( qApp->applicationDirPath() +"/"+ name");
    to load it from folder where .exe is.
    This is good for deployment time.



  • @mrjj said:

    "/home/pics/" + name"

    Indeed, it worked. Thank you :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.