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. Closing widget
QtWS25 Last Chance

Closing widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 477 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.
  • T Offline
    T Offline
    tactical77
    wrote on last edited by
    #1

    Hi,

    I'm having some problems with a connect command. I've been using the qtdesigner so far and everything worked. Now I need to code it manually. The problem is the mainwindow close but I need to close the child widget. Here's the code.

    void MainWindow::on_actionKundensuche_triggered()
    {
    
    QWidget *window = new QWidget;
    
    
    QPushButton *button1 = new QPushButton("OK");
    QPushButton *button2 = new QPushButton("Abbrechen");
    
    QLineEdit *line1 = new QLineEdit();
    
    window->setFixedSize(300, 250);
    
    
    QVBoxLayout *layout1 = new QVBoxLayout;
    layout1->addWidget(line1);
    
    QHBoxLayout *layout2 = new QHBoxLayout;
    layout2->addWidget(button1);
    layout2->addWidget(button2);
    layout1->addLayout(layout2);
    
    window->setLayout(layout1);
    
    window->show();
    
    
    connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered()));
    
      }
    
    
    void MainWindow::on_abbrechen_triggered()
    {
        close();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @tactical77 said in Closing widget:

      connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered()));

      After this do something like this:

      connect(button2, SIGNAL(clicked()), window, SLOT(deleteLater()));
      

      C++ is a perfectly valid school of magic.

      T 1 Reply Last reply
      2
      • fcarneyF fcarney

        @tactical77 said in Closing widget:

        connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered()));

        After this do something like this:

        connect(button2, SIGNAL(clicked()), window, SLOT(deleteLater()));
        
        T Offline
        T Offline
        tactical77
        wrote on last edited by
        #3

        @fcarney

        It works. Thanks a lot.

        1 Reply Last reply
        0
        • T tactical77

          Hi,

          I'm having some problems with a connect command. I've been using the qtdesigner so far and everything worked. Now I need to code it manually. The problem is the mainwindow close but I need to close the child widget. Here's the code.

          void MainWindow::on_actionKundensuche_triggered()
          {
          
          QWidget *window = new QWidget;
          
          
          QPushButton *button1 = new QPushButton("OK");
          QPushButton *button2 = new QPushButton("Abbrechen");
          
          QLineEdit *line1 = new QLineEdit();
          
          window->setFixedSize(300, 250);
          
          
          QVBoxLayout *layout1 = new QVBoxLayout;
          layout1->addWidget(line1);
          
          QHBoxLayout *layout2 = new QHBoxLayout;
          layout2->addWidget(button1);
          layout2->addWidget(button2);
          layout1->addLayout(layout2);
          
          window->setLayout(layout1);
          
          window->show();
          
          
          connect(button2, SIGNAL(clicked()), this, SLOT(on_abbrechen_triggered()));
          
            }
          
          
          void MainWindow::on_abbrechen_triggered()
          {
              close();
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @tactical77 said in Closing widget:

          void MainWindow::on_abbrechen_triggered()
          {
          close();
          }

          If you want to close the widget why do you call close() on your MainWindow?
          Call close on your widget instead:

          void MainWindow::on_abbrechen_triggered()
          {
              window->close();
          }
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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