PDA

View Full Version : wait copy picture then show it



raphaelf
3rd November 2006, 19:00
Hi everybody

QT 4.1.3 WINXP MINGW

I have a functionm that copy a picture from a server local and show it.

My function work, but sometimes the copy process is not fast and i cant see the picture.

I am searching a solution for my function, that i wait until the picture is complete copied local, and then show it.

Have somebody a idea? :crying:


void MainWindow::showPicure()
{
ui.label->clear();
QString src = (ui.listView->currentItem() )->text( 4 );
QMessageBox::information(this, "src", src);
QFileInfo file(src);
if(file.isReadable() == true)
{

Q3UrlOperator *op = new Q3UrlOperator();
QString temp_picture = "c:/temp/temp_album.jpg";
op->copy(src, temp_picture, false, false);
QMessageBox::information(this, "wait", "wait");
ui.label->setPixmap(QPixmap(temp_picture));
ui.picture_lb->setText("");
}
else
{
ui.picture_lb->setText("No Picture");
ui.label->clear();
}
}

wysota
3rd November 2006, 20:33
Use signals and slots. The url operator will tell you when it will have finished the operation. You can connect a slot to it and continue.

raphaelf
4th November 2006, 11:52
Hi wysota,

Thanks for your answer..

How could i make that? Have you a example for me? :crying:

wysota
4th November 2006, 12:30
Split your code. One part of it should contain operations to be performed before the download is finished. The other (it should be a slot) should contain operations to be started after the download will have finished. Then at the end of the first part you can use QUrlOperator and connect the second part to its finished() signal. When the download is finished, the slot will be called and your code will continue its job.

raphaelf
5th November 2006, 11:41
Hi wysota, i think i have understand now,

but my function test will never called why?



void MainWindow::showPicure()
{
ui.label->clear();
QString src = (ui.listView->currentItem() )->text( 4 );
QFileInfo file(src);
if(file.isReadable() == true)
{

Q3UrlOperator *op = new Q3UrlOperator();
QString temp_picture = "c:/temp/temp_album.jpg";
op->copy(src, temp_picture, false, false);
connect(op, SIGNAL(finished()), this, SLOT(test()));
ui.picture_lb->setText("");
}
else
{
ui.picture_lb->setText("No Picture");
ui.label->clear();
}
}
void MainWindow::test()
{
ui.label->setPixmap(QPixmap("c:/temp/temp_album.jpg"));

}

jpn
5th November 2006, 11:50
but my function test will never called why?
The signature of the signals is: finished(Q3NetworkOperation*) so it should be something like:

connect(op, SIGNAL(finished(Q3NetworkOperation*)), this, SLOT(test()));

raphaelf
5th November 2006, 12:09
Thanks JPN and Wysota it works:p :p