From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


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.


  • Lifetime Qt Champion

    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