Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Image Fetching



  • Hi All,

    Image fetching Sqlite database to label button its working fine. But at the run time i can able to fetch one image only, i need to fetch multiple image. Any one can help me.

    My code is here:
    void MainWindow::on_pushButton_3_clicked()
    {
    int id;
    if(myDB.open())//opening database
    {
    QByteArray array;
    QSqlQuery query("SELECT id,img FROM vkks");
    query.next();
    for( int i =1; i <= 2; i++ )
    {
    qDebug() << "value of id: " << id << endl;
    array = query.value(1).toByteArray();
    qDebug()<<0;
    id=query.value(0).toInt();
    qDebug()<<array;
    QPixmap pixmap = QPixmap();
    pixmap.loadFromData(array);

            ui->label_4->setNum(id);
            ui->label->setPixmap(pixmap);
            qDebug()<<id;
    
        }
    }
    

    }


  • Lifetime Qt Champion

    Hi,

    It's all described in the QSqlQuery doc:

    while (query.next()) {
            //Do what you want with the database returned value
    }
    


  • Hi,

    if i used within while loop, i can able to fetch last image only appeared, middle of the image is, i cant able to fetch.

    while (query.next())
    {
    array = query.value(1).toByteArray();
    id=query.value(0).toInt();
    QPixmap pixmap = QPixmap();
    pixmap.loadFromData(array);
    ui->label_4->setNum(id);
    ui->label->setPixmap(pixmap);
    }


  • Qt Champions 2019

    Well, you always put your current image into the same label:

    ui->label_4->setNum(id);
    ui->label->setPixmap(pixmap);
    

    That's why you see only the last image.
    You could use one label for each image.



  • @jsulm

    Hi,

    If i put each image each label mean, i need to put 300 label button, its possible???? for single form???? else, have any other way, please tell me????


  • Lifetime Qt Champion

    Create them dynamically in C++

    Or maybe consider using the Graphics View framework depending on the needs of your application


Log in to reply