Hi Janoschka,
The problem is your definition : QSpinBox *lostSpinBox
in the constructor mainwindow.
Please edit your code like this :
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
lostSpinBox
= new QSpinBox(ui
->mainToolBar
);
lostSpinBox->setMaximum(10000);
ui->mainToolBar->addWidget(lostSpinBox);
lostSpinBox->setValue(0); // here it works
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionLostReset_triggered()
{
if (ui->actionLostReset->isChecked())
{
lostSpinBox->setValue(10); // here it crashes
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
lostSpinBox = new QSpinBox(ui->mainToolBar);
lostSpinBox->setMaximum(10000);
ui->mainToolBar->addWidget(lostSpinBox);
lostSpinBox->setValue(0); // here it works
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionLostReset_triggered()
{
if (ui->actionLostReset->isChecked())
{
lostSpinBox->setValue(10); // here it crashes
}
}
To copy to clipboard, switch view to plain text mode
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSpinBox>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void on_actionLostReset_triggered();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSpinBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QSpinBox *lostSpinBox;
public slots:
void on_actionLostReset_triggered();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
Best regards,
Toto
Bookmarks