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. Update mainWindow / Reloop constructor
QtWS25 Last Chance

Update mainWindow / Reloop constructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
updatemainwindowmain looprefresh
4 Posts 3 Posters 664 Views
  • 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.
  • L Offline
    L Offline
    LoveAndMercy
    wrote on 26 Sept 2022, 12:10 last edited by
    #1

    Hello guys,

    i would like to update my mainWindow. My mainWindow searches through a directory and uses those file names for the creation of the buttons. My GUI also is able to create new Files in the descripted directory. If i close and open my GUI again, then the buttons are shown. But i would like to update the shown buttons, if a new file is added during the running of my GUI. The problem here is, that this process is only done once at the constructor of the class. So if im not wrong, myApp->update() does not work here.

    Here is the my code:

    This is the constructor of my mainWindow, which creates the amount of buttons in dependecy to the amount of files in the directory:

    mainWindow::mainWindow(const QString savedSettingsHeader, const QString subjectSettingsHeader, const QString objectSettingsHeader) {
        window = new QVBoxLayout(this);
        layoutLoadButtons = new QHBoxLayout();
    
        // Load Settings Buttons
        labelLoadButtons = new QLabel(savedSettingsHeader, this);
        layoutLoadButtons->addWidget(labelLoadButtons);
    
        savedSettingsNames = getSavedSettingsNames();
    
        // Load as many buttons as files have already been saved
        for (int i = 0; i < savedSettingsNames.size(); i++) {
            QString buttonName = savedSettingsNames.at(i)[0].c_str();
            myLoadButtons.append(new QPushButton(buttonName, this));
            layoutLoadButtons->addWidget(myLoadButtons.at(i));
        }
    
        window->addLayout(layoutLoadButtons);
    }
    

    This is the function for creating a new file, which would mean also creating a new button:

    void mainWindow::saveAsFile() {
        // Check if force value has been set
    
        string expText = qExpText.toStdString() + "-" + qSubText.toStdString() + "-" + currentDateTime();
    
        saveSettings(expText, qObjText.toStdString(), savedForceSettings);
    }
    

    What is the best way to solve this problem? I hope u guys can help me here

    J 1 Reply Last reply 26 Sept 2022, 12:14
    0
    • L LoveAndMercy
      26 Sept 2022, 12:10

      Hello guys,

      i would like to update my mainWindow. My mainWindow searches through a directory and uses those file names for the creation of the buttons. My GUI also is able to create new Files in the descripted directory. If i close and open my GUI again, then the buttons are shown. But i would like to update the shown buttons, if a new file is added during the running of my GUI. The problem here is, that this process is only done once at the constructor of the class. So if im not wrong, myApp->update() does not work here.

      Here is the my code:

      This is the constructor of my mainWindow, which creates the amount of buttons in dependecy to the amount of files in the directory:

      mainWindow::mainWindow(const QString savedSettingsHeader, const QString subjectSettingsHeader, const QString objectSettingsHeader) {
          window = new QVBoxLayout(this);
          layoutLoadButtons = new QHBoxLayout();
      
          // Load Settings Buttons
          labelLoadButtons = new QLabel(savedSettingsHeader, this);
          layoutLoadButtons->addWidget(labelLoadButtons);
      
          savedSettingsNames = getSavedSettingsNames();
      
          // Load as many buttons as files have already been saved
          for (int i = 0; i < savedSettingsNames.size(); i++) {
              QString buttonName = savedSettingsNames.at(i)[0].c_str();
              myLoadButtons.append(new QPushButton(buttonName, this));
              layoutLoadButtons->addWidget(myLoadButtons.at(i));
          }
      
          window->addLayout(layoutLoadButtons);
      }
      

      This is the function for creating a new file, which would mean also creating a new button:

      void mainWindow::saveAsFile() {
          // Check if force value has been set
      
          string expText = qExpText.toStdString() + "-" + qSubText.toStdString() + "-" + currentDateTime();
      
          saveSettings(expText, qObjText.toStdString(), savedForceSettings);
      }
      

      What is the best way to solve this problem? I hope u guys can help me here

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Sept 2022, 12:14 last edited by
      #2

      @LoveAndMercy If I understood your question correctly you need this: https://doc.qt.io/qt-6/qfilesystemwatcher.html
      Connect a slot to https://doc.qt.io/qt-6/qfilesystemwatcher.html#directoryChanged signal and in that slot add a new button for the new file.

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

      L 1 Reply Last reply 26 Sept 2022, 13:01
      4
      • J jsulm
        26 Sept 2022, 12:14

        @LoveAndMercy If I understood your question correctly you need this: https://doc.qt.io/qt-6/qfilesystemwatcher.html
        Connect a slot to https://doc.qt.io/qt-6/qfilesystemwatcher.html#directoryChanged signal and in that slot add a new button for the new file.

        L Offline
        L Offline
        LoveAndMercy
        wrote on 26 Sept 2022, 13:01 last edited by
        #3

        @jsulm Thank your very much, i was looking for this

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mchinand
          wrote on 26 Sept 2022, 13:13 last edited by mchinand
          #4

          Also, you can move the code that actually creates/adds the buttons to a separate class method and then call it from both the constructor and when you get a signal that new files were added. I am not sure what 'reloop constructor' means, but you do not want to try to call the constructor again.

          1 Reply Last reply
          1

          3/4

          26 Sept 2022, 13:01

          • Login

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