PushButton not opening window.
-
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?
-
-
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(); }
-
@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...
-
@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.....
-
@treej4 said in PushButton not opening window.:
How do I connect my slot?
-
@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 -
@treej4
Your code has asetleaderboard()
method, which seems to create theQTableWidget
, but nothing which actual calls that function.....Your
mainwindow
has aleaderboard *lb;
variable (written by you?), but nothing which would connect that toMainWindow::on_leaderboard_clicked()
....