januszmk
28th July 2011, 21:30
Hello.
I want to have variable number of threads in my application depends of settings.
I am using QtConcurrent::run because then I can run any function of any class.
I did something like this:
QVector<QFuture<void> > asda;
for(i=0; i<n; i++)
{
asda[i] = QtConcurrent::run(this, &MainWindow::thr1);
}
for(i=0; i<n; i++)
{
asda[i].waitForFinished();
}
but when it is runing MainWindow::thr1 for the second time, then I get aplication error and:
app.exe exited with code -1073741819
my header file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <mailbox.h>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QtCore>
#include <QFileDialog>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void upd(int numer, int percent, int speed);
void on_pushButton_3_clicked();
void on_pushButton_2_clicked();
private:
QStandardItem *item;
QStandardItemModel *model;
Ui::MainWindow *ui;
std::string generate();
mailbox *mailb[8];
void thr1();
QString dir;
void download();
};
#endif // MAINWINDOW_H
and MainWindow::thr1 function is just for testing:
void MainWindow::thr1()
{
qDebug() << "test";
}
What am I doing wrong?
I would be grateful, if someone could help.
Janusz
I want to have variable number of threads in my application depends of settings.
I am using QtConcurrent::run because then I can run any function of any class.
I did something like this:
QVector<QFuture<void> > asda;
for(i=0; i<n; i++)
{
asda[i] = QtConcurrent::run(this, &MainWindow::thr1);
}
for(i=0; i<n; i++)
{
asda[i].waitForFinished();
}
but when it is runing MainWindow::thr1 for the second time, then I get aplication error and:
app.exe exited with code -1073741819
my header file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <mailbox.h>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QtCore>
#include <QFileDialog>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void upd(int numer, int percent, int speed);
void on_pushButton_3_clicked();
void on_pushButton_2_clicked();
private:
QStandardItem *item;
QStandardItemModel *model;
Ui::MainWindow *ui;
std::string generate();
mailbox *mailb[8];
void thr1();
QString dir;
void download();
};
#endif // MAINWINDOW_H
and MainWindow::thr1 function is just for testing:
void MainWindow::thr1()
{
qDebug() << "test";
}
What am I doing wrong?
I would be grateful, if someone could help.
Janusz