QT中循环显示图片和简单的显示图片

请关注我的github

https://github.com/linqiaozhou
以下实例代码不久后将会上传到我的github
这是我最近一个项目中的部分代码
//以下是简单的在QT中显示图片的代码
this->imageOrg = new QImage();

    if(fileName != "")

    {

        if(imageOrg->load(fileName))

        {

 

            this->scene = new QGraphicsScene;

            *imageOrg=imageOrg->scaled(ui->View1->width()-10,ui->View1->height()-10,Qt::IgnoreAspectRatio);

            scene->addPixmap(QPixmap::fromImage(*imageOrg));

            ui->View1->setScene(scene);

           //ui->graphicsView->resize(image->width() + 10, image->height() + 10);

            ui->View1->show();

 

        }

 

    }

}
//循环显示图片的代码
void  MainWindow::autoplay()    //自动播放函数
{
    QString fileName = QFileDialog::getOpenFileName(
               this, "Open Image File",
              ".",
            "Image files (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *.xbm *.xpm);;All files (*.*)");
    if(fileName != "")
    {
        ui->vedioLabel->setPixmap(fileName);
        update();
    }
 
    //以下步骤得到上层路径并求得图像序列号
    int len=fileName.length()-1;
    while(fileName[len]!='/')
    {
      len--;
    }
    stringstream os;
    string s=fileName.toStdString();
    os<<s[len+1];
    os<<s[len+2];
    os>>indexVedio;
    os.str("");
    QString fileDir(len);
    for(int i=0;i
    {
        fileDir[i]=fileName[i];
    }
 
    imgDirVideo.setPath(fileDir);
    QStringList filter ;
    filter << "*.jpg" << "*.bmp" << "*.jpeg" << "*.png" << "*.xpm" ;
    imgListVideo =imgDirVideo.entryList(filter, QDir::Files |QDir::NoSymLinks,QDir::Name) ;
 
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(cdPicture()));
   // QString framRate=ui->text3->toPlainText();
    timer->start(100);//定时器,每隔100MS秒刷新
 
}
 
 
//下面的子函数更改显示的帧数
void MainWindow::cdPicture()
{
   //pixImage.load(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(1));
 
   indexVedio++;
   if(indexVedio==MaxIndex)
   {
     if (timer->isActive())
     {
         timer->stop();
 
     }
 
     QMessageBox::information(this,"End","The Last Frame");
     return ;
   }
   ui->vedioLabel->setPixmap(imgDirVideo.absolutePath() + QDir::separator()+ imgListVideo.at(indexVedio));
   update();
}
 
 
QT中信号与槽的简单示例:
private slots:

      void on_slotOpenImage_triggered(); //信号槽

connect(ui->OpenImageBtn,SIGNAL(clicked()), this, SLOT(on_slotOpenImage_triggered()));
原文地址:https://www.cnblogs.com/qiaozhoulin/p/4509938.html