I have created an app which is used to display folders and files in c++ and Qt.
I have added an info section which is supposed to display the number of files and folders.
To do saw, I have created a layout and widgets as below:
void MainWindow::createInfoSection()
{
uint64_t space;
CreateInfoSection = new QWidget();
CreateInfoSection->setFixedHeight(40);
//QGridLayout *CreateInfoLayout = new QGridLayout(CreateInfoSection);
CreateInfoLayout = new QGridLayout(CreateInfoSection);
NbOfFolderLabel = new QLabel(tr("%1 Folders").arg(m_device.getNbOfFolder()));
NbOfFilesLabel = new QLabel(tr("%1 Files").arg(m_device.getNbOfFiles()));
space = m_device.getAvailableFreeSpaceInBytes();
if(space < MEGABYTE)
SpaceAvailLabel = new QLabel(tr("%1 KB Remaining").arg(space/KILOBYTE));
else if (space < GIGABYTE)
SpaceAvailLabel = new QLabel(tr("%1 MB Remaining").arg(space/MEGABYTE));
else
SpaceAvailLabel = new QLabel(tr("%1 GB Remaining").arg(space/GIGABYTE));
NbOfFolderLabel->updatesEnabled();
NbOfFilesLabel->updatesEnabled();
SpaceAvailLabel->updatesEnabled();
CreateInfoLayout->addWidget(NbOfFolderLabel, 0,0);
CreateInfoLayout->addWidget(NbOfFilesLabel, 0,1);
CreateInfoLayout->addWidget(SpaceAvailLabel, 0,2);
CreateInfoLayout->setAlignment(Qt::AlignCenter);
}
And when an action is done such as adding a Folder, I'm calling a Refresh method as below:
void MainWindow::RefreshInfoSection()
{
uint64_t space;
NbOfFolderLabel = new QLabel(tr("%1 Files").arg(m_device.getNbOfFolder()));
NbOfFilesLabel = new QLabel(tr("%1 Files").arg(m_device.getNbOfFiles()));
space = m_device.getAvailableFreeSpaceInBytes();
if(space < MEGABYTE)
SpaceAvailLabel = new QLabel(tr("%1 KB Available").arg(space/KILOBYTE));
else if (space < GIGABYTE)
SpaceAvailLabel = new QLabel(tr("%1 MB Available").arg(space/MEGABYTE));
else
SpaceAvailLabel = new QLabel(tr("%1 GB Available").arg(space/GIGABYTE));
NbOfFolderLabel->update();
NbOfFilesLabel->update();
SpaceAvailLabel->update();
CreateInfoLayout->update();
}
But it never works even if the 3 labels are updated.
Any idea ?