Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Basic Program unexpectedly finished
Forum Updated to NodeBB v4.3 + New Features

Basic Program unexpectedly finished

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bluestreak
    wrote on last edited by
    #1

    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;
    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

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

        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. :-)

        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

        • Login

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