Reputation: 25
I'm trying to code a C++ function to save a selected picture to my program directory, using a Qt GUI.
So far, the "save" function I'm using on my QPixmap object won't save anything, and I can't figure out why.
Here is the code :
qImage = new QPixmap(path);
QPixmap qImage2 = qImage->scaled(this->width(),this->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
qImage2.toImage();
qImage2.save(QDir::currentPath());
qDebug()<<QDir::currentPath();
Can anyone help me ? :)
Upvotes: 1
Views: 1993
Reputation: 4404
QDir::currentPath()
returns the current working directory. Obviously, the filename itself is not specified. Simply append the needed filename, for example: QDir::currentPath() + "/123.png"
QPixmap::toImage()
is a const method returning a QImage
converted from a QPixmap
. It literally does nothing useful in your code, remove it or use QImage
instead.
QDir::currentPath()
returns the current working directory which is not necessarily an application executable directory. Use QCoreApplication::applicationDirPath()
instead if you need an executable directory.Upvotes: 1