Results 1 to 3 of 3

Thread: QToolbar: Trying to reset value of QSpinBox in QToolbar via QToolbutton results crash

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolbar: Trying to reset value of QSpinBox in QToolbar via QToolbutton results c

    Hi Janoschka,
    The problem is your definition : QSpinBox *lostSpinBox
    in the constructor mainwindow.

    Please edit your code like this :
    MainWindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. lostSpinBox = new QSpinBox(ui->mainToolBar);
    10. lostSpinBox->setMaximum(10000);
    11. ui->mainToolBar->addWidget(lostSpinBox);
    12. lostSpinBox->setValue(0); // here it works
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    19.  
    20. void MainWindow::on_actionLostReset_triggered()
    21. {
    22. if (ui->actionLostReset->isChecked())
    23. {
    24. lostSpinBox->setValue(10); // here it crashes
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QSpinBox>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. QSpinBox *lostSpinBox;
    22.  
    23. public slots:
    24. void on_actionLostReset_triggered();
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Best regards,

    Toto

  2. #2
    Join Date
    Oct 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Red face Re: QToolbar: Trying to reset value of QSpinBox in QToolbar via QToolbutton results c

    Hi Toto!
    Thank you very, very much!!!!

    I was so dumb and blind, because after your posting I realised I made the correct things in mainwindow.h, but I made some kind of redefinition in mainwindow.c.

    Sometimes it's better to have someone to look at the code....

    Have a nice day

Similar Threads

  1. Unable to add QToolButton to QToolbar on QWidget
    By rawfool in forum Qt Programming
    Replies: 0
    Last Post: 17th August 2012, 10:52
  2. Hiding a QToolButton in a QToolBar
    By elcuco in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2009, 20:35
  3. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:11
  4. QToolBar
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 19:48
  5. QToolBar help
    By Erlendhg in forum Qt Programming
    Replies: 2
    Last Post: 6th November 2006, 15:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.