I have a program which has class MainWindow that inherited from QMainWindow.
I want to run a specific function in a new thread. 
Since I can't inherit from QThread so the best solution is to use QtConcurrent.
I stored QtConcurrent result in a QFuture but as mentioned in the QT documentation, the result of QtConcurrent can not be canceled by QFuture::cancel.
I see some questions like mine but the answers are to create a class which inherit from QThread that I can't.
So what is the solution?
Here is my codes:
mainwindow.h:
using namespace  std;
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    ...
private:
    Ui::MainWindow *ui;
    ...
    QFuture<void> future;
    QFutureWatcher< void > futureWatcher;
    QPushButton *stop_pushButton_=new QPushButton;
private slots:
    ...
    void on_graph_pushButton_clicked();
    void generateGraph();
    void stopPushButtonClicked();
    };
mainwindow.cpp:
void MainWindow::stopPushButtonClicked()
{
    futureWatcher.setFuture(future);
    futureWatcher.cancel();
    futureWatcher.waitForFinished();
}
   ...
void MainWindow::on_graph_pushButton_clicked()
{
    loadingOn();
    future = QtConcurrent::run(this,&MainWindow::generateGraph);
}
void MainWindow::generateGraph()
{
    InsertLogs::getInstance()->printStatus(USER_GENERATE_GRAPH);
    GenGraph* gr=new GenGraph;
    connect(this,&MainWindow::loadingOffSignal,this,&MainWindow::loadingOff);
    graphType_=gr->generateGraph(persons_comboBox_->currentText(),
                      ui->graphResource1_comboBox->currentText(),
                      ui->graphResource2_comboBox->currentText(),
                      ui->graphType_comboBox->currentText());
    InsertLogs::getInstance()->printSuccess(SYSTEM_GENERATE_GRAPH);
    emit loadingOffSignal();
}
When I click on graph_pushButton, generatedGraph is called in a new thread, but when I click on stop_pushButton the future does not stop and the generatedGraph function executes completely.