简体   繁体   中英

Saving a file with a custom extension

I have a program I wrote in Windows with this piece of code that works on Windows, but when compiled in linux, the saved file doesn't have the .l2p extension.

void MainWindow::on_saveButton_clicked()
 {
     QString fileName = QFileDialog::getSaveFileName(this,
         tr("Salvesta Projekt"), "",
         tr("Latid Pindalaks (*.l2p)"));

     if (fileName.isEmpty())
         return;
     ...

What should I do?

If the file name doesn't have the extension you need, just add it:

QString fileName = QFileDialog::getSaveFileName(this,
    tr("Salvesta Projekt"), "",
    tr("Latid Pindalaks (*.l2p)"));

if (fileName.isEmpty())
    return;

if (!fileName.endsWith(".l2p"))
    fileName += ".l2p";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM