Results 1 to 5 of 5

Thread: [Qt5] Set Default Suffix

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Location
    Temecula, CA
    Posts
    19
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default [Qt5] Set Default Suffix

    I made a small program that saves a file, but people who use Ubuntu say that they can't properly save the file without manually putting a file extension in the save file name. I tried using the setDefaultSuffix function though I don't see how it would fit with the getSaveFileName function that I'm using.

    Here's my code for the save button:
    Qt Code:
    1. void MainWindow::on_save_clicked()
    2. {
    3. if (pngData.isEmpty())
    4. {
    5. QPixmap noSaveData(":/graphic/noSaveData.png");
    6. ui->preview->setStyleSheet("background: transparent ;");
    7. ui->preview->setPixmap(noSaveData);
    8. return;
    9. }
    10. QString filename = QFileDialog::getSaveFileName(this, ("Save Skin"), "C:/Users/", ("PNG Image (*.png)"));
    11. QFile file(filename);
    12. file.open(QIODevice::WriteOnly);
    13. file.write(pngData);
    14. file.close();
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [Qt5] Set Default Suffix

    Qt Code:
    1. QFileDialog::getSaveFileName(0,"Save Skin",QDir::homePath(),"PNG Image (*.png)");
    To copy to clipboard, switch view to plain text mode 
    there is no C:/Users in Linux ...read The Current Directory and Other Special Paths
    http://doc.qt.io/qt-4.8/QDir
    Last edited by alrawab; 14th February 2013 at 04:47.

  3. The following user says thank you to alrawab for this useful post:

    Salads (14th February 2013)

  4. #3
    Join Date
    Jan 2013
    Location
    Temecula, CA
    Posts
    19
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [Qt5] Set Default Suffix

    Thanks for the tip, the save function now goes to the directory I want, however I get weird error output since I added it in:
    output.jpg
    Qt Code:
    1. QFSFileEngine::open: No file name specified
    2. Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
    3. Cannot create accessible interface for object: QPushButton(0x8f4880, name = "save")
    4. Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
    5. Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
    6. Cannot create accessible interface for object: QPushButton(0x8f4880, name = "save")
    7. Cannot create accessible interface for object: QPushButton(0xa77478, name = "dLoad")
    8. Cannot create accessible interface for object: QLineEdit(0xa774d8, name = "lineEdit")
    9. Cannot create accessible interface for object: QPushButton(0x8f4880, name = "save")
    10. Cannot create accessible interface for object: QLabel(0x8f4900, name = "preview")
    11. Cannot create accessible interface for object: QPushButton(0x8f4960, name = "clear")
    12. Cannot create accessible interface for object: QWidget(0xa77418, name = "centralWidget")
    13. Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
    14. Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
    To copy to clipboard, switch view to plain text mode 

    Everything seems to be working regardless, besides the missing extensions that Linux users have.

    EDIT: The errors don't seem related to QDir, as I changed it back just to check and had the same result.
    Last edited by Salads; 14th February 2013 at 05:13.

  5. #4
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [Qt5] Set Default Suffix

    its works fine if we supposed pngData is correct data type
    Qt Code:
    1. #include <QApplication>
    2. #include <QFileDialog>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc,argv);
    7. QString filename =QFileDialog::getSaveFileName(0,"Save Skin",QDir::homePath(),"PNG Image (*.png)");
    8. QFile file(filename);
    9. file.open(QIODevice::WriteOnly);
    10. file.write("Foo");//change Foo to your data
    11.  
    12. file.close();
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 
    QPixmap::save
    Last edited by alrawab; 14th February 2013 at 05:29.

Similar Threads

  1. Qt Creator Exotic C++ Suffix
    By redruM in forum Qt Tools
    Replies: 4
    Last Post: 29th November 2012, 09:23
  2. Replies: 13
    Last Post: 19th June 2011, 21:04
  3. Replies: 0
    Last Post: 17th December 2010, 08:50
  4. suffix for qt dlls
    By jobrandt in forum Installation and Deployment
    Replies: 6
    Last Post: 11th April 2008, 09:59
  5. how to add suffix to library like qtcore4_gcc.dll
    By furk in forum Installation and Deployment
    Replies: 3
    Last Post: 13th June 2007, 15:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.