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. Reuse QPlainTextEdit window after it's closed
Forum Updated to NodeBB v4.3 + New Features

Reuse QPlainTextEdit window after it's closed

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 234 Views
  • 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.
  • N Offline
    N Offline
    neshone
    wrote on last edited by
    #1

    I'm using QPlainTextEdit as a view for my log. I want it to show in a separate window, so it's created without a parent and I call show() when I want it to appear - this part is fine.

    I also don't want to lose the log when the log window is closed (user clicks on 'X'), so the widget is not deleted on close, but instead I reuse it by calling show() again when I want it to appear next. Unfortunately, when the window is shown the second time, as soon new content is appended (via keyboard or through code) and the QPlainTextEdit tries to scroll, the whole application crashes.

    It seems that the problem is in closing because everything works fine if I hide the widget instead of closing it. The problem is that the documentation states that when closed, the widget is only hidden if Qt::WA_DeleteOnClose attibute is not set (it isn't set in my case) and not deleted (which is true, because the destructor is not called). However, from my testing, it seems that close is doing more than just calling hide.

    Am I doing something wrong? Is there a proper way to reuse a widget as a top-level window? Is it supported at all? I haven't found anything in the docs that implies it isn't.

    Here's a small example to reproduce the problem:

    #include <QApplication>
    #include <QPushButton>
    #include <QPlainTextEdit>
    
    int main(int argc, char* argv[]) {
        QApplication app(argc, argv);
        QPushButton button;
        QPlainTextEdit edit;
    
        button.setText("SHOW");
        QObject::connect(&button, &QPushButton::clicked, &edit, [&edit](bool checked) {
            edit.show();
        });
    
        button.show();
        app.exec();
        return 0;
    }
    

    Steps to reproduce the issue:

    1. Click the "SHOW" button.
    2. Close the newly opened window containing QPlainTextEdit.
    3. Click the "SHOW" button again.
    4. Press "Enter" inside the new window several times until the QPlainTextEdit needs to scroll. The application should crash.

    I'm using Qt 5.12.4

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Known bug, please update to 5.12.5

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

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