PDA

View Full Version : Problem with QLabel



jaca
20th May 2008, 19:18
Hello!
In my program this function below is called once when I opened.
It read the file and updates the QLabel "title" with setText().


void Mpl::updateFiles()
{

QFile file("mpl.dat");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;

QTextStream in(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
while (!in.atEnd()) {
QString line = in.readLine();
uplist << line;
}
QApplication::restoreOverrideCursor();
file.close();
if (uplist.count() == 3){
title->setText(uplist.at(0));
path = uplist.at(1);
path2 = uplist.at(2);
}else{
QMessageBox::warning(this, "Error reading File",
"The file should contain: name of the project and paths.");
}
}

In the programme it is possible to change the file "mpl.dat". Then the user can click a QPushButton and call updateFiles () again. But the upgrade of QLabel "title" does not occur.
Someone help me, please?
Thanks

JimDaniel
20th May 2008, 21:43
Try calling title->adjustSize() after you set the text. You should always call that after you set a QLabel to another value that might not be the same size. You may even want to call title->clear() before you set the text.

lyuts
29th May 2008, 14:15
Hello!
In my program this function below is called once when I opened.
It read the file and updates the QLabel "title" with setText().


void Mpl::updateFiles()
{

QFile file("mpl.dat");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;

QTextStream in(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
while (!in.atEnd()) {
QString line = in.readLine();
uplist << line;
}
QApplication::restoreOverrideCursor();
file.close();
if (uplist.count() == 3){
title->setText(uplist.at(0));
path = uplist.at(1);
path2 = uplist.at(2);
}else{
QMessageBox::warning(this, "Error reading File",
"The file should contain: name of the project and paths.");
}
}

In the programme it is possible to change the file "mpl.dat". Then the user can click a QPushButton and call updateFiles () again. But the upgrade of QLabel "title" does not occur.
Someone help me, please?
Thanks

Are you sure that after each update of mpl.dat your uplist.count() is equal to 3?