title: qt pixmap.save not working
body: <p>In my screenshot taking project the QPixmap.save() function returns false meaning fails every time. However when I copy the example project from Qt page <a href="http://qt-project.org/doc/qt-5/qtwidgets-desktop-screenshot-example.html" rel="nofollow">http://qt-project.org/doc/qt-5/qtwidgets-desktop-screenshot-example.html</a>, it works. Thus it rules out Windows 7 issue with file permissions.</p>
  
  <p>So I wonder why it fails? </p>
  
  <p>widget.h file:</p>
  
  <pre><code>namespace Ui {
  class Widget;
  }
  
  class Widget : public QWidget
  {
      Q_OBJECT
  
  public:
      explicit Widget(QWidget *parent = 0);
      ~Widget();
  
  private slots:
      void updateTimer();
      void startScreenshots();
      void stopScreenshots();
      void takeScreenshot();
  private:
      Ui::Widget *ui;
  
  
      QString initialPath;
      QPixmap currentScreenshot;
      QSpinBox * delaySpinBox;
      QPushButton * startButton;
      QPushButton * stopButton;
      QHBoxLayout * hboxLayout;
      QGroupBox * groupBox;
      QTimer * timer;
      void setInitialPath();
      void addStuff();
  };
  </code></pre>
  
  <p>widget.cpp</p>
  
  <pre><code>#include "widget.h"
  #include "ui_widget.h"
  
  Widget::Widget(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::Widget)
  {
      ui-&gt;setupUi(this);
      setInitialPath();
  
      addStuff();
  }
  
  Widget::~Widget()
  {
      delete ui;
  }
  
  void Widget::updateTimer()
  {
      timer-&gt;stop();
      int milisecs = delaySpinBox-&gt;value() *1000;
      timer-&gt;start( milisecs );
  }
  
  void Widget::startScreenshots()
  {
      timer-&gt;start( delaySpinBox-&gt;value() * 1000 );
  }
  
  void Widget::stopScreenshots()
  {
      timer-&gt;stop();
  }
  
  void Widget::takeScreenshot()
  {
      //take screenshot
      currentScreenshot = QPixmap::grabWindow(QApplication::desktop()-&gt;winId());
  
      //save screenshot
      QString format = "png";
  
      QDateTime local( QDateTime::currentDateTime() );
      QString date = local.toString();
      QString fileName = initialPath + date;
  
      if(!currentScreenshot.save(fileName, format.toLatin1().constData()) )
      {
          qDebug() &lt;&lt; "didnt save\n";
          QMessageBox::information(this,"failed to save","failed to save");
      }
  }
  
  void Widget::setInitialPath()
  {
      initialPath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
        "/home",
        QFileDialog::ShowDirsOnly
         | QFileDialog::DontResolveSymlinks);
  }
  
  void Widget::addStuff()
  {
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(takeScreenshot()) );
  
    delaySpinBox = new QSpinBox(this);
    delaySpinBox-&gt;setValue(60);
    delaySpinBox-&gt;setSuffix(tr(" s"));
    connect( delaySpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateTimer()) );
  
    startButton = new QPushButton(this);
    startButton-&gt;setText("start");
    connect(startButton,SIGNAL(clicked()),this,SLOT(startScreenshots()) );
  
    stopButton = new QPushButton(this);
    stopButton-&gt;setText("stop");
    connect(stopButton,SIGNAL(clicked()),this,SLOT(stopScreenshots()) );
  
    hboxLayout = new QHBoxLayout(this);
    hboxLayout-&gt;addWidget(startButton);
    hboxLayout-&gt;addWidget(stopButton);
    hboxLayout-&gt;addWidget(delaySpinBox);
  
    groupBox = new QGroupBox(tr("Options"));
    groupBox-&gt;setLayout(hboxLayout);
  
    setLayout(hboxLayout);
  }
  </code></pre>