c++qtqtcoreqfiledialogqfileinfo

Copy path to QString


I need to copy the full filepath, without filename, into a QString from QFileDialog below.

  QString fileName = QFileDialog::getOpenFileName(this,
      tr("Select app to install"), '/' , tr("APK Files (*.apk)"));

Solution

  • You use QString QFileInfo::absolutePath() const for this. See the documentation for details.

    QFileInfo fileInfo(QFileDialog::getOpenFileName(this,
      tr("Select app to install"), '/' , tr("APK Files (*.apk)")));
    qDebug() << fileInfo.absolutePath();