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.cpp
    @MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {

    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::lightGray);
    this->setAutoFillBackground(true);
    this->setPalette(p);
    this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
    
    mplayer_wrapper *cameras = new mplayer_wrapper("rtsp://169.254.133.191/output","rtsp://169.254.133.193/output");
    centralWidget()->layout()->addWidget(cameras);
    

    }
    @

    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) :
    QWidget(parent)
    {
    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::black);
    this->setAutoFillBackground(true);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    this->setPalette(p);
    this->setMinimumSize(720,576);
    this->setMaximumSize(1440,576);
    }@

    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

    Hi,

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

    @centralWidget()->layout()->addWidget(cameras);@

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

    @setCentralWidget(cameras);@

    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.