Insertion Image in the Database.



  • Hi all,

    How to image insert in the database. Already i insert one way. fetching time only path(string format) appeared. Image doesn't appeared.

    this is my code.

    if(qry.exec("SELECT groupname,imageurl FROM grouptable;"))
    {
    int recCount = 0;
    while( qry.next() )
    {
    recCount++;
    }

                        if(recCount>0)
                        {
                            qry.first();
                            qry.previous();
                            PRINT <<"Query sucess";
                            ui->list->clear();
                            ui->list->setFont(QFont("Ubuntu",10));
                            while(qry.next())
                            {
                                //adding the group name to the list view
                                ui->list->addItem(new QListWidgetItem(QIcon(qry.value(1).toString()),qry.value(0).toString()));
                            }
                        }
                        else
                        {
                            PRINT<<"table empty"<<endl;
                        }
                    }
    

    anyone help me.


  • Lifetime Qt Champion

    Hi,

    Did you check that the path are valid to create your icons ?



  • Hi,

    This is my full code. I check it, valid path only. fetching time string only appeared.

                if(db.open())
                {
                    QSqlQuery qry;
                    PRINT<<QString("SELECT groupid FROM grouptable where groupname=\"%1\";").arg(group)<<endl;
                    //checking for the group id under the group name which is selected
                    if(qry.exec(QString("SELECT groupid FROM grouptable where groupname=\"%1\";").arg(group)))
                    {
                        int recCount = 0;
                        while( qry.next() )
                        {
                            recCount++;
                        }
    
                        if(recCount>0)
                        {
                            qry.first();
                            PRINT <<"Query sucess"<<endl;
                            tempval=qry.value(0).toInt();
                            groupid=tempval;
                        }
                        else
                        {
                            PRINT<<"table empty"<<endl;
                        }
                    }
                    else
                    {
                        PRINT <<"Error .." << db.lastError().text()<<endl;
    
                    }
    
    
                    PRINT<<QString("SELECT categoryname FROM category where groupid=%1 order by categoryid ASC;").arg(tempval)<<endl;
                    //checking the category name under that group id
                    if(qry.exec(QString("SELECT categoryname FROM category where groupid=%1 order by categoryid ASC;").arg(tempval)))
                    {
                        int recCount = 0;
                        while( qry.next() )
                        {
                            recCount++;
                        }
    
                        if(recCount>0)
                        {
                            qry.first();
                            qry.previous();
                            PRINT <<"Query sucess"<<endl;
                            ui->list->clear();
                            ui->list->setFont(QFont("Ubuntu",7));
                            while(qry.next())
                            {
                                //adding categorys to list
                                ui->list->addItem(qry.value(0).toString());
                            }
                        }
                        else
                        {
                            PRINT<<"table empty"<<endl;
                        }
                    }
                    else
                    {
                        PRINT <<"Error .." << db.lastError().text()<<endl;
    
                    }
                }

  • Lifetime Qt Champion

    Where exactly in these query are you querying for an image ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.