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. The window in the task bar does not appear
Forum Updated to NodeBB v4.3 + New Features

The window in the task bar does not appear

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 4 Posters 5.0k 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.
  • M Mask

    @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.

    J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #6

    @Mask
    my guess would be your homeui has no size defined and defaulted therefor to a size of 0x0


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    M 1 Reply Last reply
    1
    • J.HilkJ J.Hilk

      @Mask
      my guess would be your homeui has no size defined and defaulted therefor to a size of 0x0

      M Offline
      M Offline
      Mask
      wrote on last edited by
      #7

      @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:
      0_1539619689118_Desktop Screenshot 2018.10.15 - 18.06.59.55.png

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #8

        Can you show how you start your application and how you use your login widget ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        0
        • SGaistS SGaist

          Can you show how you start your application and how you use your login widget ?

          M Offline
          M Offline
          Mask
          wrote on last edited by
          #9

          @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.

          jsulmJ 1 Reply Last reply
          0
          • M Mask

            @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.

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

            @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;
            }
            

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

            J.HilkJ M 2 Replies Last reply
            3
            • jsulmJ jsulm

              @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;
              }
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #11

              @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~~


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              jsulmJ 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @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~~

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

                @J.Hilk Thanks, corrected! Was a copy/paste :-)

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

                1 Reply Last reply
                1
                • jsulmJ jsulm

                  @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;
                  }
                  
                  M Offline
                  M Offline
                  Mask
                  wrote on last edited by Mask
                  #13

                  @jsulm
                  What is "logedOn ()"?

                  jsulmJ 1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mask
                    wrote on last edited by
                    #14

                    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.

                    1 Reply Last reply
                    0
                    • M Mask

                      @jsulm
                      What is "logedOn ()"?

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

                      @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.

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

                      M 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @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.

                        M Offline
                        M Offline
                        Mask
                        wrote on last edited by
                        #16

                        @jsulm
                        But the "main.cpp" endlessly repeats an if until it's true?
                        Is it okay like I did?

                        jsulmJ 1 Reply Last reply
                        0
                        • M Mask

                          @jsulm
                          But the "main.cpp" endlessly repeats an if until it's true?
                          Is it okay like I did?

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

                          @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.

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

                          M 1 Reply Last reply
                          1
                          • jsulmJ jsulm

                            @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.

                            M Offline
                            M Offline
                            Mask
                            wrote on last edited by
                            #18

                            @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?

                            jsulmJ 1 Reply Last reply
                            0
                            • M Mask

                              @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?

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

                              @Mask "SecDialogPage->exec()" returns as soon as user closes dialog either by accepting (OK) or rejecting (Cancel).

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

                              M 1 Reply Last reply
                              1
                              • jsulmJ jsulm

                                @Mask "SecDialogPage->exec()" returns as soon as user closes dialog either by accepting (OK) or rejecting (Cancel).

                                M Offline
                                M Offline
                                Mask
                                wrote on last edited by
                                #20

                                @jsulm
                                Ah okay, thank you!

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Mask
                                  wrote on last edited by Mask
                                  #21

                                  Sorry for yet the disorder, but I can't declare a global variable, should be a variable qsqldatabase, I also tried to create another header files but there are unsuccessful.
                                  How can I do?

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • M Mask

                                    Sorry for yet the disorder, but I can't declare a global variable, should be a variable qsqldatabase, I also tried to create another header files but there are unsuccessful.
                                    How can I do?

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

                                    @Mask You don't need a QSqlDatabase instance and even less so a global variable!
                                    Please take a look at the documentation and example there: http://doc.qt.io/qt-5/qsqldatabase.html

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

                                    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