Re: [Qt5] Set Default Suffix
Code:
QFileDialog::getSaveFileName(0,
"Save Skin",
QDir::homePath(),
"PNG Image (*.png)");
there is no C:/Users in Linux ...read The Current Directory and Other Special Paths
http://doc.qt.io/qt-4.8/QDir
1 Attachment(s)
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:
Attachment 8717
Code:
Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
Cannot create accessible interface
for object
: QPushButton(0x8f4880, name
= "save") Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
Cannot create accessible interface
for object
: QPushButton(0x8f4880, name
= "save") Cannot create accessible interface
for object
: QPushButton(0xa77478, name
= "dLoad") Cannot create accessible interface
for object
: QLineEdit(0xa774d8, name
= "lineEdit") Cannot create accessible interface
for object
: QPushButton(0x8f4880, name
= "save") Cannot create accessible interface
for object
: QLabel(0x8f4900, name
= "preview") Cannot create accessible interface
for object
: QPushButton(0x8f4960, name
= "clear") Cannot create accessible interface
for object
: QWidget(0xa77418, name
= "centralWidget") Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
Cannot create accessible interface for object: MainWindow(0x33fbd4, name = "MainWindow")
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.
Re: [Qt5] Set Default Suffix
its works fine if we supposed pngData is correct data type
Code:
#include <QApplication>
#include <QFileDialog>
int main(int argc, char **argv)
{
file.write("Foo");//change Foo to your data
file.close();
return 0;
}
QPixmap::save
Re: [Qt5] Set Default Suffix
Added after 4 minutes:
I think I want to keep it as a QByteArray because I use the .clear() functions for a clear button in the downloader. (It's a small minecraft skin downloader)
Would the QFileDialog::setDefaultSuffix work here? How would I implement it?
Here's my full code:
header:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QNetworkReply>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
QNetworkAccessManager *manager;
private slots:
void on_dLoad_clicked();
void replyFinished(QNetworkReply *reply);
void on_save_clicked();
void on_clear_clicked();
void on_lineEdit_returnPressed();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QIcon>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDebug>
#include <QFileDialog>
#include <QFile>
#include <QDir>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("Minecraft Skin Downloader v0.7"); //Version
QIcon icon
(":/graphic/ico.png");
setWindowIcon(icon);
setFixedSize(400, 200);
setStyleSheet("QMainWindow { background-image: url( :/graphic/bg.png); } ");
setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
ui->lineEdit->setToolTip("Username (Case Sensitive)");
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_dLoad_clicked()
{
//s3.amazonaws.com/MinecraftSkins/NICKNAME.png
QString prefix
= "http://s3.amazonaws.com/MinecraftSkins/";
QString usrl
= prefix
+= ui
->lineEdit
->text
() += ".png";
QNetworkRequest request(url);
manager->get(request);
}
void MainWindow::replyFinished(QNetworkReply *reply)
{
if(reply->error() != QNetworkReply::NoError)
{
qDebug() <<"Error in" << reply->url() << ":" << reply->errorString();
QPixmap noUsr
(":/graphic/voidUser.png");
ui->preview->setStyleSheet("background: transparent ;");
ui->preview->setPixmap(noUsr);
pngData.clear();
return;
}
pngData = reply->readAll();
srcPic.loadFromData(pngData);
QPixmap scaled
= srcPic.
scaled(128,
64, Qt
::KeepAspectRatio, Qt
::FastTransformation);
ui->preview->setStyleSheet("QLabel { background-color: white ;}");
ui->preview->setPixmap(scaled);
}
void MainWindow::on_save_clicked()
{
if (pngData.isEmpty())
{
QPixmap noSaveData
(":/graphic/noSaveData.png");
ui->preview->setStyleSheet("background: transparent ;");
ui->preview->setPixmap(noSaveData);
return;
}
QString filename
= QFileDialog::getSaveFileName(this, tr
("Save Skin"),
QDir::homePath(), tr
("PNG Image(*.png)"));
file.write(pngData);
file.close();
}
void MainWindow::on_clear_clicked()
{
pngData.clear();
ui->preview->clear();
ui->preview->setStyleSheet("background: transparent ;");
ui->lineEdit->clear();
}
void MainWindow::on_lineEdit_returnPressed()
{
on_dLoad_clicked();
}
Added after 47 minutes:
Alright so I may have found a way around it, but I'm not sure if it would work since I don't have a Linux computer.
Code:
void MainWindow::on_save_clicked()
{
if (pngData.isEmpty())
{
QPixmap noSaveData
(":/graphic/noSaveData.png");
ui->preview->setStyleSheet("background: transparent ;");
ui->preview->setPixmap(noSaveData);
return;
}
QString filename
= QFileDialog::getSaveFileName(this, tr
("Save Skin"),
QDir::homePath(), tr
("PNG Image(*.png)"));
if(fi.suffix().isEmpty())
{
fi.suffix() = "png";
}
file.write(pngData);
file.close();
}
Would this work?