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. Creating a class object "wrapper" inside the mainwindow constructor makes the main window not visible [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k 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.
  • I Offline
    I Offline
    ion_knight
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ion_knight
        wrote on last edited by
        #3

        Ha epic fail thanks SGaist knew it was something stupid.

        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