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. PushButton not opening window.
Forum Updated to NodeBB v4.3 + New Features

PushButton not opening window.

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

    I have a QDialog class window called leaderboard that has a QTableWidget within it. My goal is that from my mainwindow when I push the button called leaderboard, it opens the leaderboard window. I have a void on_leaderboard_clicked(); method that just has the pointer set the modal and show. But when I run the project and click on the button, nothing happens. Any advice?

    JonBJ 1 Reply Last reply
    0
    • T treej4

      I have a QDialog class window called leaderboard that has a QTableWidget within it. My goal is that from my mainwindow when I push the button called leaderboard, it opens the leaderboard window. I have a void on_leaderboard_clicked(); method that just has the pointer set the modal and show. But when I run the project and click on the button, nothing happens. Any advice?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @treej4
      Hello and welcome.

      There is not enough information to answer from this. Show your relevant code, including the connect() and the body of on_leaderboard_clicked(). Have you put a qDebug() inside the slot to see whether it is called?

      JonBJ 1 Reply Last reply
      1
      • T Offline
        T Offline
        treej4
        wrote on last edited by
        #3

        Hmm well I do not have a connect() but here let me show you what I have.

        leaderboard.h

        public:
            explicit leaderboard(QWidget *parent = nullptr);
            void setleaderboard();
            int row = 0;
            int col = 0;
            ~leaderboard();
        
        private slots:
            void on_pushButton_clicked();
        
        private:
            Ui::leaderboard *ui;
            QGraphicsScene *scene;
            QTableWidget *table;
        
        

        leaderboard.cpp

        leaderboard::leaderboard(QWidget *parent) :
            QDialog(parent),
            ui(new Ui::leaderboard)
        {
            ui->setupUi(this);
        }
        
        leaderboard::~leaderboard()
        {
            delete ui;
        }
        
        void leaderboard::on_pushButton_clicked(){
            this->close();
        }
        
        void leaderboard::setleaderboard(){
            QTableWidget *table = new QTableWidget(this);
            table->setRowCount(row);
            table->setColumnCount(col);
        
            QStringList labels;
            labels << "Name:" << "Wins:" << "Games Played:" << "Wins/Losses:";
            table->setHorizontalHeaderLabels(labels);
        }
        

        mainwindow.h

        #include "leaderboard.h"
        private slots:
             void on_leaderboard_clicked();
        private:
        leaderboard *lb;
        

        mainwindow.cpp

        void MainWindow::on_leaderboard_clicked(){
        
            //lb->setModal(true);
            lb = new leaderboard(this);
            lb->show();
            //lb.close();
        }
        
        
        jsulmJ 1 Reply Last reply
        0
        • T treej4

          Hmm well I do not have a connect() but here let me show you what I have.

          leaderboard.h

          public:
              explicit leaderboard(QWidget *parent = nullptr);
              void setleaderboard();
              int row = 0;
              int col = 0;
              ~leaderboard();
          
          private slots:
              void on_pushButton_clicked();
          
          private:
              Ui::leaderboard *ui;
              QGraphicsScene *scene;
              QTableWidget *table;
          
          

          leaderboard.cpp

          leaderboard::leaderboard(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::leaderboard)
          {
              ui->setupUi(this);
          }
          
          leaderboard::~leaderboard()
          {
              delete ui;
          }
          
          void leaderboard::on_pushButton_clicked(){
              this->close();
          }
          
          void leaderboard::setleaderboard(){
              QTableWidget *table = new QTableWidget(this);
              table->setRowCount(row);
              table->setColumnCount(col);
          
              QStringList labels;
              labels << "Name:" << "Wins:" << "Games Played:" << "Wins/Losses:";
              table->setHorizontalHeaderLabels(labels);
          }
          

          mainwindow.h

          #include "leaderboard.h"
          private slots:
               void on_leaderboard_clicked();
          private:
          leaderboard *lb;
          

          mainwindow.cpp

          void MainWindow::on_leaderboard_clicked(){
          
              //lb->setModal(true);
              lb = new leaderboard(this);
              lb->show();
              //lb.close();
          }
          
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @treej4 said in PushButton not opening window.:

          Hmm well I do not have a connect()

          So, you depend on Qt auto-connect feature which is known for being unrelyable? You should consider using explicit connect() calls to connect signals with slots.

          And did you do what @JonB suggested? Add a debug output to your slot to see whether it is called at all...

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

          1 Reply Last reply
          3
          • JonBJ JonB

            @treej4
            Hello and welcome.

            There is not enough information to answer from this. Show your relevant code, including the connect() and the body of on_leaderboard_clicked(). Have you put a qDebug() inside the slot to see whether it is called?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @treej4

            @JonB said in PushButton not opening window.:

            Have you put a qDebug() inside the slot to see whether it is called?

            Surely you want to act on that? Either your slot is not connected to your signal or your slot's code does not do what you want/think. Putting in a debug message will tell you/us which it is.....

            1 Reply Last reply
            0
            • T Offline
              T Offline
              treej4
              wrote on last edited by
              #6

              It doesn't print anything in my debug. How do I connect my slot? I thought what I have is all I needed to get the next window to pop-up.

              jsulmJ M JonBJ 3 Replies Last reply
              0
              • T treej4

                It doesn't print anything in my debug. How do I connect my slot? I thought what I have is all I needed to get the next window to pop-up.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @treej4 said in PushButton not opening window.:

                How do I connect my slot?

                https://doc.qt.io/qt-5/signalsandslots.html

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

                1 Reply Last reply
                0
                • T treej4

                  It doesn't print anything in my debug. How do I connect my slot? I thought what I have is all I needed to get the next window to pop-up.

                  M Offline
                  M Offline
                  mpergand
                  wrote on last edited by
                  #8

                  @treej4 said in PushButton not opening window.:

                  It doesn't print anything in my debug. How do I connect my slot? I thought what I have is all I needed to get the next window to pop-up.

                  Since you are using a ui file, you need to look here:
                  https://doc.qt.io/qt-5/designer-connection-mode.html

                  1 Reply Last reply
                  0
                  • T treej4

                    It doesn't print anything in my debug. How do I connect my slot? I thought what I have is all I needed to get the next window to pop-up.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #9

                    @treej4
                    Your code has a setleaderboard() method, which seems to create the QTableWidget, but nothing which actual calls that function.....

                    Your mainwindow has a leaderboard *lb; variable (written by you?), but nothing which would connect that to MainWindow::on_leaderboard_clicked()....

                    1 Reply Last reply
                    1

                    • Login

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