Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Qt4 - Program written in QtCreator segfaults

[solved] Qt4 - Program written in QtCreator segfaults

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nexuiz
    wrote on last edited by
    #1

    The following code is suppose to change a property of a progress bar when a button is clicked.
    I tried to do the same in Qt3Designer and everything worked fine.
    What happens is as soon as the button is clicked, the program crashes with the following message:

    Starting /home/user/qt4/test1/test1...
    The program has unexpectedly finished.
    /home/user/qt4/test1/test1 exited with code 0

    Here's mainwindow.cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "kled.h"
    #include <QLCDNumber>
    #include <QProgressBar>

    QProgressBar *qprogressbar;
    QLCDNumber *lcdnumber;
    KLed *kled;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::changeEvent(QEvent *e)
    {

    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
    

    }

    void MainWindow::on_pushButton_clicked()
    {
    qprogressbar->setValue(30);
    }

    @

    Thank you.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Where are you instantiating qprogressbar?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nexuiz
        wrote on last edited by
        #3

        Thanks for your quick reply.
        Disclaimer: I am not a C++ programmer. I just create frontends for my C based console programs that drive my instruments.

        Back to my post now, I thought that QtCreator did it automatically (pretty much like in Qt3-Designer).
        I mean since all widgets already were placed on the form, then they should already have been instantiated, right?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Based on your comments, I'm assuming you have a widget in the Ui named qprogressbar?

          If so, you need to get rid of line 7 in your code above ( (It doesn't refer to the progressbar in your ui. It's just an unused global pointer) , and replace line 42 with
          @
          ui->qprogressbar->setValue(30)
          @
          as anything that is created in the Ui file will be available through that pointer. There's no need to redeclare pointers for the Ui widgets in your code.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nexuiz
            wrote on last edited by
            #5

            That worked. Next stop: get the fundamentals of C++.

            Thank you very much.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved