Unsolved The window in the task bar does not appear
-
Hi, I tried to open a new QMainWindow after logging in, but the program in the taskbar does not appear.
mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QGraphicsScene> #include <QtSql> #include "home.h" namespace Ui { class Login; } class Login : public QMainWindow { Q_OBJECT public: explicit Login(QWidget *parent = 0); ~Login(); void Wait(int Seconds); void LoadDatabase(); void ShowHome(); struct Users { QString Username; QString Password; int AdminLevel; } UsersInfo; QSqlDatabase database; private slots: void on_Login_AccessButton_clicked(); void on_Login_DeleteButton_clicked(); private: Ui::Login *LoginUI; Home *HomeUI; }; #endif // MAINWINDOW_H
A part of mainwindow.cpp
hide(); HomeUI = new Home(this); HomeUI->show();
Thank you all and sorry for my bad english.
-
Hi and welcome to devnet,
What do you mean by: "the program in the task bar does not appear" ?
Also, why are you making your login widget a QMainWindow ?
What version of Qt are you using ?
What OS are you running on ? -
Hi, thanks for the reply.
I mean that after making the Switch of QMainWindow the application disappears at the bottom and it is as if it were not executed and if I try to minimize it appears in a small window in the bottom left (if I have not explained, I send you a screen as soon as I go back from school).
I'm new to programming with graphics, but with the tutorials I saw, I noticed that everyone used the QMainWindow.
The version I use is 5.11 and I use it on Windows. -
@Mask Why don't you use QDialog for your Login instead of QMainWindow? Create QMainWindow only if log-in was successful.
-
@jsulm said in The window in the task bar does not appear:
@Mask Why don't you use QDialog for your Login instead of QMainWindow? Create QMainWindow only if log-in was successful.
I've just tried, the result does not change after login does not appear in the taskbar.
Thanks anyway.
-
@Mask
my guess would be your homeui has no size defined and defaulted therefor to a size of 0x0 -
@J.Hilk
The quantities are defined, I also tried to set LoginUI as a window to open after login but nothing has changed.An example of my problem:
-
Can you show how you start your application and how you use your login widget ?
-
@SGaist
Of course.secdialog.cpp:
#include "secdialog.h" #include "ui_secdialog.h" #include <QtSql> #include <QCryptographicHash> #include <QMessageBox> #include <QtSql> SecDialog::SecDialog(QWidget *parent) : QDialog(parent), SecDialogUI(new Ui::SecDialog) { SecDialogUI->setupUi(this); SecDialogUI->Login_ErrorLabel->hide(); setWindowIcon(QIcon(":/Image/mask.png")); LoadDatabase(); } SecDialog::~SecDialog() { delete SecDialogUI; } void SecDialog::LoadDatabase() { QString driver = "QMYSQL"; database = QSqlDatabase::addDatabase(driver); database.setDatabaseName("clients"); database.setHostName("localhost"); database.setUserName("root"); database.setPassword(""); if (!database.open() ) { QMessageBox Error; Error.setText("Problemi di accesso al Database! \nContatta un'amministratore di rete."); Error.exec(); exit(1); } database.close(); } void SecDialog::Wait(int Seconds) { QTime dieTime= QTime::currentTime().addSecs(Seconds); while (QTime::currentTime() < dieTime) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } void SecDialog::on_Login_AccessButton_clicked() { if(!SecDialogUI->Login_ErrorLabel->isHidden() ) { SecDialogUI->Login_ErrorLabel->hide(); Wait(1); } QString Username = SecDialogUI->Login_UsernameInput->text(); QString Password = SecDialogUI->Login_PasswordInput->text(); if(Username == NULL || Password == NULL) SecDialogUI->Login_ErrorLabel->show(); else { database.open(); QSqlQuery QuerySQL; QuerySQL.prepare("SELECT * FROM users WHERE username = '"+Username+"'"); QuerySQL.exec(); database.close(); if(QuerySQL.size() < 1) SecDialogUI->Login_ErrorLabel->show(); else { QuerySQL.next(); UsersInfo.Username = QuerySQL.value("username").toString(); UsersInfo.Password = QuerySQL.value("password").toString(); UsersInfo.AdminLevel = QuerySQL.value("admin_level").toInt(); } QString CryptPassword = QCryptographicHash::hash(Password.toLocal8Bit(), QCryptographicHash::Md5).toHex(); if(UsersInfo.Password == CryptPassword && UsersInfo.AdminLevel > 0) { this->close(); MainWindowUI = new MainWindow(this); MainWindowUI->showMaximized(); } else SecDialogUI->Login_ErrorLabel->show(); } }
Main.cpp:
#include "secdialog.h" #include <QApplication> #include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); SecDialog SecDialogPage; SecDialogPage.setWindowFlags (SecDialogPage.windowFlags () & (~Qt::WindowContextHelpButtonHint) ); SecDialogPage.show(); return a.exec(); }
secdialog.h
#ifndef SECDIALOG_H #define SECDIALOG_H #include <QDialog> #include <QGraphicsScene> #include <QtSql> #include "mainwindow.h" namespace Ui { class SecDialog; } class SecDialog : public QDialog { Q_OBJECT public: explicit SecDialog(QWidget *parent = 0); ~SecDialog(); void Wait(int Seconds); void LoadDatabase(); struct Users { QString Username; QString Password; int AdminLevel; } UsersInfo; QSqlDatabase database; private slots: void on_Login_AccessButton_clicked(); private: Ui::SecDialog *SecDialogUI; MainWindow *MainWindowUI; }; #endif // SECDIALOG_H
Thanks for the help you are giving me.
-
@Mask You shoud change your design: this dialog should not show the main window (in fact it should not know anything about main window). Do it like this:
int main(int argc, char *argv[]) { QApplication a(argc, argv); SecDialog *SecDialogPage = new SecDialog(); SecDialogPage->setWindowFlags (SecDialogPage.windowFlags () & (~Qt::WindowContextHelpButtonHint) ); SecDialogPage->exec(); if (SecDialogPage->logedOn()) { MainWindowUI = new MainWindow(); MainWindowUI->showMaximized(); } SecDialogPage->deleteLater(); int ret = a.exec(); delete MainWindowUI; return ret; }
-
@jsulm said in The window in the task bar does not appear:
> MainWindowUI = new MainWindow(this);parenting to~~this
shouldn't be possible inside main -
@J.Hilk Thanks, corrected! Was a copy/paste :-)
-
@jsulm
What is "logedOn ()"? -
I found a solution:
int main(int argc, char *argv[]) { QApplication a(argc, argv); SecDialog *SecDialogPage = new SecDialog(); SecDialogPage->setWindowFlags(Qt::Window); if(SecDialogPage->exec() == QDialog::Accepted) { MainWindow *MainWindowPage = new MainWindow(); MainWindowPage->showMaximized(); } SecDialogPage->deleteLater(); return a.exec(); }
Thank you all for the help you gave me.
-
@Mask said in The window in the task bar does not appear:
What is "logedOn ()"?
It would be a method in your dialog implemented by you. Returns true when user has successfully logged on, else false.
-
@jsulm
But the "main.cpp" endlessly repeats an if until it's true?
Is it okay like I did? -
@Mask said in The window in the task bar does not appear:
But the "main.cpp" endlessly repeats an if until it's true?
No, it does not - I don't see any loop there.
The code you posted works if you only return QDialog::Accepted in case user was logged on successfully and exiting the app if not. -
@jsulm
I know that no loops are set, but I'm wondering when the main executes that one. Does it only run after the accept () is called? -
@Mask "SecDialogPage->exec()" returns as soon as user closes dialog either by accepting (OK) or rejecting (Cancel).
-
@jsulm
Ah okay, thank you!