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. Dialog displayed late
Qt 6.11 is out! See what's new in the release blog

Dialog displayed late

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 535 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.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #1

    Hi, I've a problemi with a Dialog.
    I've this code:

    QString ImportExportMap::ImportMap(QStringList *InfoData)
    {
        QString FileName;
    
        FileName = QFileDialog::getOpenFileName(this, "MAP File", cMapArchive, "File map (*.map)");
    
        if(FileName.isEmpty()) return NULL;
    
        QFileInfo f(FileName);
        FileName = f.fileName();
    
        QDialog *Dlg = new QDialog;
        Dlg->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
        QHBoxLayout *h = new QHBoxLayout;
        Dlg->setLayout(h);
        QLabel *l = new QLabel("Loading file, please wait...");
        h->addWidget(l);
        Dlg->show();
    
        QFile InputFile(cMapArchive+"/"+FileName);
        if (InputFile.open(QIODevice::ReadOnly))
        {
            QTextStream in(&InputFile);
            while (!in.atEnd())
            {
                 ...
            }
        }
    
        InputFile.close();
        Dlg->close();
        delete Dlg;
    
        return FileName;
    }
    
    
    

    The problem is that Dlg is shown late, when the file has already been loaded.
    How I can starts with loading file only if Dlg is completely shown?
    Thanks.

    JonBJ 1 Reply Last reply
    0
    • S Stefanoxjx

      Hi, I've a problemi with a Dialog.
      I've this code:

      QString ImportExportMap::ImportMap(QStringList *InfoData)
      {
          QString FileName;
      
          FileName = QFileDialog::getOpenFileName(this, "MAP File", cMapArchive, "File map (*.map)");
      
          if(FileName.isEmpty()) return NULL;
      
          QFileInfo f(FileName);
          FileName = f.fileName();
      
          QDialog *Dlg = new QDialog;
          Dlg->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
          QHBoxLayout *h = new QHBoxLayout;
          Dlg->setLayout(h);
          QLabel *l = new QLabel("Loading file, please wait...");
          h->addWidget(l);
          Dlg->show();
      
          QFile InputFile(cMapArchive+"/"+FileName);
          if (InputFile.open(QIODevice::ReadOnly))
          {
              QTextStream in(&InputFile);
              while (!in.atEnd())
              {
                   ...
              }
          }
      
          InputFile.close();
          Dlg->close();
          delete Dlg;
      
          return FileName;
      }
      
      
      

      The problem is that Dlg is shown late, when the file has already been loaded.
      How I can starts with loading file only if Dlg is completely shown?
      Thanks.

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

      @Stefanoxjx said in Dialog displayed late:

      How I can starts with loading file only if Dlg is completely shown?

      Split your function into two separate ones. The first one ends at Dlg->show();. The remainder of your code should be in a function called from the QDialog::showEvent() method, which is called when a widget is actually shown. You will need to subclass QDialog for your dialog to achieve that, so that you can override that method. You might have your overridden method emit a signal, so that your ImportExportMap class can put a slot on that and you can keep the code in the ImportExportMap class rather than having to put it in the sub-classed dialog code, as you please.

      Given your usage, a rather dirty/naughty way may be to put QCoreApplication::processEvents() after your current Dlg->show();. That might be enough to just show the dialog initially, I'm not sure.

      Note that Qt has a QProgressDialog, or even a QProgressBar class, which you might prefer to use, since all you seem to want the dialog for is to inform the user while loading/parsing the file, and you may find simpler/preferable to the above.

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by
        #3

        Hi JonB, thanks for your help.
        I used QDialog::showEvent :)

        1 Reply Last reply
        0

        • Login

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