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. QWidget displays 'black window"
Forum Updated to NodeBB v4.3 + New Features

QWidget displays 'black window"

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 600 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.
  • P Offline
    P Offline
    Poldi
    wrote on last edited by
    #1

    This is a follow on to this

    https://forum.qt.io/topic/154394/cannot-get-second-qwidget-window-to-show?_=1708302629937

    I'm trying to find out why the QWidget::show doesn't display the screen as expected.

    I've got a Widget that displays the connections status and waits for the continue or Cancel button to be pressed.

    #include "connectionstatus.h"
    #include "ui_connectionstatus.h"
    
    class Controller;
    
    ConnectionStatus::ConnectionStatus(QWidget *parent)
        : QWidget(parent)
        , ui_(new Ui::ConnectionStatus)
    {
        ui_->setupUi(this);
        ui_->connectionStatus->setReadOnly(true);
        QWidget::connect(ui_->continueButton, &QAbstractButton::pressed, this, &ConnectionStatus::Continue );
        QWidget::connect(ui_->cancelButton, &QAbstractButton::pressed, this, &ConnectionStatus::Cancel );
    }
    
    ConnectionStatus::~ConnectionStatus()
    {
        delete ui_;
    }
    
    bool ConnectionStatus::statusOk()
    {
        return statusOk_;
    }
    
    void ConnectionStatus::DisplayText(QString text)
    {
        ui_->connectionStatus->setText(text);
    }
    
    void ConnectionStatus::Continue()
    {
        statusOk_= true;
    }
    
    void ConnectionStatus::Cancel()
    {
        statusOk_ = false;
    }
    
    

    I have a controller class that displays the connection status and acts on which button is pressed.

    void Controller::Init(QString ipAddr, int port)
    {
        ipAddr_ = ipAddr;
        port_ = port;
        connection_->Init(ipAddr_, port_);
    
        statusWindow_ = new ConnectionStatus();
        statusWindow_->activateWindow();
        statusWindow_->DisplayText("Connected to Server at " + ipAddr_ + " Port " + QString::number(port_));
        statusWindow_->show();
    }
    

    While trying to figure out why this isn't working as I expect, I'm usinf the debugger and found that if I step through the controller code, after I step past statusWindow_->show() I get a window to pop up, but it has no content Displays this.png
    If I run the code without the debugger I get this. Should display this.png

    At what stage does the show() display the window 'correctly?
    Thanks

    C 1 Reply Last reply
    0
    • P Poldi

      This is a follow on to this

      https://forum.qt.io/topic/154394/cannot-get-second-qwidget-window-to-show?_=1708302629937

      I'm trying to find out why the QWidget::show doesn't display the screen as expected.

      I've got a Widget that displays the connections status and waits for the continue or Cancel button to be pressed.

      #include "connectionstatus.h"
      #include "ui_connectionstatus.h"
      
      class Controller;
      
      ConnectionStatus::ConnectionStatus(QWidget *parent)
          : QWidget(parent)
          , ui_(new Ui::ConnectionStatus)
      {
          ui_->setupUi(this);
          ui_->connectionStatus->setReadOnly(true);
          QWidget::connect(ui_->continueButton, &QAbstractButton::pressed, this, &ConnectionStatus::Continue );
          QWidget::connect(ui_->cancelButton, &QAbstractButton::pressed, this, &ConnectionStatus::Cancel );
      }
      
      ConnectionStatus::~ConnectionStatus()
      {
          delete ui_;
      }
      
      bool ConnectionStatus::statusOk()
      {
          return statusOk_;
      }
      
      void ConnectionStatus::DisplayText(QString text)
      {
          ui_->connectionStatus->setText(text);
      }
      
      void ConnectionStatus::Continue()
      {
          statusOk_= true;
      }
      
      void ConnectionStatus::Cancel()
      {
          statusOk_ = false;
      }
      
      

      I have a controller class that displays the connection status and acts on which button is pressed.

      void Controller::Init(QString ipAddr, int port)
      {
          ipAddr_ = ipAddr;
          port_ = port;
          connection_->Init(ipAddr_, port_);
      
          statusWindow_ = new ConnectionStatus();
          statusWindow_->activateWindow();
          statusWindow_->DisplayText("Connected to Server at " + ipAddr_ + " Port " + QString::number(port_));
          statusWindow_->show();
      }
      

      While trying to figure out why this isn't working as I expect, I'm usinf the debugger and found that if I step through the controller code, after I step past statusWindow_->show() I get a window to pop up, but it has no content Displays this.png
      If I run the code without the debugger I get this. Should display this.png

      At what stage does the show() display the window 'correctly?
      Thanks

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @Poldi The QWidget::show() results in a spontaneous show event to draw the widget client area. This will be acted upon when the program reaches the Qt event loop. When you are stopped after show(), but before returning from Init() the Qt event loop has yet to be reached.

      P C 2 Replies Last reply
      3
      • C ChrisW67

        @Poldi The QWidget::show() results in a spontaneous show event to draw the widget client area. This will be acted upon when the program reaches the Qt event loop. When you are stopped after show(), but before returning from Init() the Qt event loop has yet to be reached.

        P Offline
        P Offline
        Poldi
        wrote on last edited by
        #3

        @ChrisW67 Thanks, but when I set a break in controller_->DoWork();, the window is still black

        void MainWindow::connect()
        {
            ipAddress_ = ui_->ipAddress->text();
            port_ = ui_->port->value();
            ui_->connectButton->setEnabled(false);
            controller_->Init(ipAddress_, port_);
            controller_->DoWork();
            qDebug() << "Window popup";
        }
        
        
        1 Reply Last reply
        0
        • C ChrisW67

          @Poldi The QWidget::show() results in a spontaneous show event to draw the widget client area. This will be acted upon when the program reaches the Qt event loop. When you are stopped after show(), but before returning from Init() the Qt event loop has yet to be reached.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @ChrisW67 said in QWidget displays 'black window":

          This will be acted upon when the program reaches the Qt event loop.

          Qt requires your code to fall through and return control to the Qt event loop, i.e. this should be the default "resting" state of your application. Until DoWork() and this MainWindow::connect() finish execution that has not happened.

          P 1 Reply Last reply
          1
          • C ChrisW67

            @ChrisW67 said in QWidget displays 'black window":

            This will be acted upon when the program reaches the Qt event loop.

            Qt requires your code to fall through and return control to the Qt event loop, i.e. this should be the default "resting" state of your application. Until DoWork() and this MainWindow::connect() finish execution that has not happened.

            P Offline
            P Offline
            Poldi
            wrote on last edited by
            #5

            @ChrisW67 Thanks, that makes sense.

            1 Reply Last reply
            0
            • P Poldi has marked this topic as solved on

            • Login

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