Results 1 to 5 of 5

Thread: Saving a QPixmap Object problem

  1. #1
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Saving a QPixmap Object problem

    Hi, i want to save a QPixmap object as File.png...
    Qt Code:
    1. format=QtCore.QString("png") #to QString.
    2. intitialPath=QtCore.QDir.currentPath()+"/snapshot"+str(self.counter)+"."+format
    3.  
    4. fileName=QtGui.QFileDialog.getSaveFileName(self, "Save As", intitialPath, "PNG Files (*.png);;All Files (*.*)" )
    5. if not fileName.isEmpty():
    6. self.originalPixamp.save(fileName, format.toAscii())
    7. self.counter += 1
    To copy to clipboard, switch view to plain text mode 
    self.counter is just for formatting the snapshot name.

    Error:
    self.originalPixamp.save(fileName, QtCore.QString(format.toAscii()))
    TypeError: argument 2 of QPixmap.save() has an invalid type
    However, in C++ i used it the same way and it works ?!

    I'm using PyQt4
    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving a QPixmap Object problem

    toAscii() returns a QByteArray. Use "PNG" or toAscii().constData() instead.

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

    StrikerX (13th November 2007)

  4. #3
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a QPixmap Object problem

    toAscii() returns a QByteArray. Use "PNG" or toAscii().constData() instead.
    Thanks,
    Qt Code:
    1. self.originalPixmap.save(fileName, format.toAscii().data())
    To copy to clipboard, switch view to plain text mode 
    works fine.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving a QPixmap Object problem

    Why not
    python Code:
    1. self.originalPixmap.save(filename, "PNG")
    To copy to clipboard, switch view to plain text mode 
    ?

  6. #5
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a QPixmap Object problem

    Actually any 'd have worked, but the problem was about Spelling !
    Wrong variable_name:
    Qt Code:
    1. self.originalPixamp
    To copy to clipboard, switch view to plain text mode 
    It should be: self.originalPixmap,

    Thanks again.

Similar Threads

  1. Problem with my object hierarchy
    By rage in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 09:18
  2. Replies: 3
    Last Post: 15th April 2007, 19:16
  3. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07
  4. problem with saving QCstrings
    By nass in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2006, 15:12

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.