mythread.cpp
MyThread
::MyThread(QObject *parent
) :{
}
void MyThread::run()
{
IMG.load("img.jpg");
PAINTER.begin(&IMG);
PEN.setColor("#ff0000");
PAINTER.setOpacity(0.30); //This string
PAINTER.setPen(PEN);
PAINTER.drawText( 20, 20, "Test"); //crash this method
IMG.save("done.jpg");
}
MyThread::MyThread(QObject *parent) :
QThread(parent)
{
}
void MyThread::run()
{
QImage IMG;
QPainter PAINTER;
QPen PEN;
IMG.load("img.jpg");
PAINTER.begin(&IMG);
PEN.setColor("#ff0000");
PAINTER.setOpacity(0.30); //This string
PAINTER.setPen(PEN);
PAINTER.drawText( 20, 20, "Test"); //crash this method
IMG.save("done.jpg");
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
MThread = new MyThread();
MThread->start();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MThread = new MyThread();
MThread->start();
}
To copy to clipboard, switch view to plain text mode
This code don't work
_______________________________________
mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
IMG.load("img.jpg");
PAINTER.begin(&IMG);
PEN.setColor("#ff0000");
PAINTER.setOpacity(0.30);
PAINTER.setPen(PEN);
PAINTER.drawText( 20, 20, "Test");
IMG.save("done.jpg");
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QImage IMG;
QPainter PAINTER;
QPen PEN;
IMG.load("img.jpg");
PAINTER.begin(&IMG);
PEN.setColor("#ff0000");
PAINTER.setOpacity(0.30);
PAINTER.setPen(PEN);
PAINTER.drawText( 20, 20, "Test");
IMG.save("done.jpg");
}
To copy to clipboard, switch view to plain text mode
This code works fine
Bookmarks