QT Creator - How can I store/save selected file to project directory

800 Views Asked by At

I am trying to create a way to store file's in the project directory. I am using QFileDialog for the dialog and using Qfile::copy() to copy the selected file. I was able to get it to work by storing it outside the project directory (Desktop). But for this, I need it to store in the project directory.

I am more than happy to provide additional information if needed.

Note: I tried storing it in the Resource folder as well without success. BTW, I am new to qt development world.

QString filePath = QFileDialog::getOpenFileName(this, QObject::tr("PDF files"),
                                                "C:/", "PDF (*.pdf) ;; JPG (*.jpg) ;; PNG (*.png)");

QFileInfo file(filePath);
QString fileName= file.fileName();

if(QFile::copy(filePath, ":/PDF/PDF/"+fileName))
    qDebug() << "success";
else
    qDebug() << "FAILED TO LOAD TO -> :/PDF/PDF/"+fileName;
0

There are 0 best solutions below