Thanks guys...but I'm not sure if this would work for me.
I guess I should explain what I am trying to do.
I have a program that lets the user choose a directory that contains a series of Tiff files and view each one, one at a time.
I declared an int called "filenum" and set = 0.
The user will choose a browse button that SIGNALS the SLOT(browse())
Once the user chooses the directory, a lineedit is updated with the path, and the getfiles funtion is called using the path from browse.
In the get function, a list of Tiff files is created. This has to occur only once, but I would like to immediately preview the first Tiff image. Hence, immediately call the loadimage function. (This is of course where my QStringList is created)
The loadimage function (using the directory path and files from QStringList and the filenum would load the firstimage.
A "next" button would increment filenum++ and call loadimage again.
Here is my code:
void ImagePreview::browse()
{
tr
("Set Directory"),
QDir::currentPath());
lineEdit->setText(directory);
getFiles(directory);
}
void ImagePreview
::getFiles(const QString &dir
)
{
loadImage();
}
void ImagePreview::loadImage()
{
QString filename
= lineEdit
->text
();
int f = filenum;
filename += files->at(f);
if (!filename.isNull()){
QMessageBox::information(this, tr
("Photoshed Image Load"),
tr("Cannot load %1.").arg(filename));
return;
}
imageLabel->setPixmap(picture.scaledToWidth(200));
fileLabel->setText(files->at(f));
a = picture.hasAlpha();
w = picture.width();
h = picture.height();
wlabel += wint;
widthLabel->setText(wlabel);
hlabel += hint;
heightLabel->setText(hlabel);
if (a){
alphaLabel->setText("<b>Alpha Channel: <font color=green>ON</font></b>");
} else {
alphaLabel->setText("<b>Alpha Channel: <font color=red>OFF</font></b>");
}
}
void ImagePreview::next()
{
if (filenum > files->size()){
return;
}
filenum++;
loadImage();
}
void ImagePreview::browse()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Set Directory"),QDir::currentPath());
lineEdit->setText(directory);
getFiles(directory);
}
void ImagePreview::getFiles(const QString &dir)
{
QString filename = "*.TIF";
QDir directory = QDir(dir);
QStringList files;
files = directory.entryList(QStringList(filename),
QDir::Files | QDir::NoSymLinks);
loadImage();
}
void ImagePreview::loadImage()
{
QString filename = lineEdit->text();
int f = filenum;
filename += files->at(f);
QImage image(filename);
if (!filename.isNull()){
QMessageBox::information(this, tr("Photoshed Image Load"),
tr("Cannot load %1.").arg(filename));
return;
}
QPixmap picture = QPixmap::fromImage(image);
imageLabel->setPixmap(picture.scaledToWidth(200));
fileLabel->setText(files->at(f));
a = picture.hasAlpha();
w = picture.width();
h = picture.height();
QString wint(QString::number(w, 10));
QString hint(QString::number(h, 10));
QString wlabel("<b>Width: </b>");
wlabel += wint;
widthLabel->setText(wlabel);
QString hlabel("<b>Height: </b>");
hlabel += hint;
heightLabel->setText(hlabel);
if (a){
alphaLabel->setText("<b>Alpha Channel: <font color=green>ON</font></b>");
} else {
alphaLabel->setText("<b>Alpha Channel: <font color=red>OFF</font></b>");
}
}
void ImagePreview::next()
{
if (filenum > files->size()){
return;
}
filenum++;
loadImage();
}
To copy to clipboard, switch view to plain text mode
I of course get an error that "files" hasn't been initialized in loadImage().
Wysota suggested making getfiles a function with a QStringList return, but where am I returning that and how am I calling that from browse().
Sorry for being such a newbie!
Bookmarks