Basic Program unexpectedly finished



  • I'm trying to run a pretty basic program which implements some tabs, which have buttons on their pages. I have it written out in both C++ and done int the design .ui. However, when I try to run the program I get the message: "The program has unexpectedly finished." Does anyone have any idea what is causing this in the code below?

    @
    #include <QtGui/QApplication>
    #include "mainwindow.h"
    #include <QPushButton>
    #include <QTabWidget>
    #include <QVBoxLayout>
    #include <QGridLayout>
    #include <QTranslator>

    QWidget *backView();
    QVBoxLayout *videoSelect();

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.resize(1280, 242);
    QTabWidget tabs;
    QWidget *view = backView();
    QVBoxLayout video = videoSelect();
    tabs.addTab(view, "Rear View");
    tabs.addTab((QWidget
    )video, "Camera Select");
    //w.addWidget(tabs);
    tabs.show();
    w.show();
    return a.exec();
    }

    QWidget *backView() {
    QPushButton *tbd = new QPushButton("TBD");
    return tbd;
    }

    QVBoxLayout *videoSelect() {
    QVBoxLayout *camChoice = new QVBoxLayout;
    QGridLayout *cameras = new QGridLayout;
    for(int i = 0; i < 16; i++){
    QPushButton button = new QPushButton("Camera " + i);
    cameras->addWidget(button, i / 4, i % 4);
    }
    camChoice->addWidget((QWidget
    )cameras);
    //vid =
    //camChoice->addWidget(vid);
    return camChoice;
    }
    @


  • Moderators

    Try adding:
    @
    w.setCentralWidget(tabs);
    @

    You will probably need to change it into a pointer, though. And maybe reparent, if it is not done automatically. Also, try debugging to see where exactly does it fail.


  • Moderators

    Your friendly neighborhood debugger should be able to tell you the exact spot where the program is crashing. That would probably be a good place to start looking. :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.