Creating a class object "wrapper" inside the mainwindow constructor makes the main window not visible [SOLVED]

  • Currently trying to create a QWidget inside mainwindows constructor, however once I create the object inside the mainwindow constructor the mainwindow never shows. Any files not listed are identical to the default.

    @MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)

    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::lightGray);
    this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
    mplayer_wrapper *cameras = new mplayer_wrapper("rtsp://","rtsp://");


    I have commented out everything inside the constructor of mplayer_wrapper so that it's only creating a black window.

    @mplayer_wrapper::mplayer_wrapper(QString cam_1, QString cam_2,QWidget *parent) :
    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::black);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    If anyone has an idea why this is failing to launch I would be very grateful. As can't see where I am going wrong at the moment as the only thing I don't have is that I didn't create a ui form during project creation (as I am doing all my layout in code so thought that wasn't necessary). Hopefully someone can point me in the right direct before I pull my hair out.

  • Lifetime Qt Champion


    Don't you by any chance rather have a crash ?


    You didn't' set any central widget, at least from the code your posted.


    Should do what you want.

  • Ha epic fail thanks SGaist knew it was something stupid.

Log in to reply

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