I'm running Qt 5.70 32-bit with x86 MinGW 32-bit on Windows 7 Pro 64-bit SP1.
In Qt Creator 4.0.2 the following mainwindow.cpp file (and other associated files - the usual) compiles successfully to ImageTest.exe in the debug folder of the build.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
{
image.load("tux.png");
imagePainter.
drawImage(QPoint(0,
0), image
);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *event)
{
QImage image;
image.load("tux.png");
QPainter imagePainter(this);
imagePainter.drawImage(QPoint(0, 0), image);
}
To copy to clipboard, switch view to plain text mode
After copying tux.png to the build's debug folder, RUN (from within Qt Creator) just produces a blank screen.
But, if I actually go to the debug folder and click on ImageTest.exe the image is properly displayed.
Alternatively, if I replace "tux.png" in the above code's image.load line with the file's full path, Qt Creator's RUN shows the image correctly.
Furthermore, if I put the image file directly in the build folder (instead of in its debug sub-folder) it works correctly from Qt Creator but then, clicking ImageTest.exe in the debug folder produces a blank screen.
Where do I need to put the image file so that it will be properly accessed both when RUNning from Qt Creator and when directly clicking ImageTest.exe?
Bookmarks