Unsolved Reading image from QSqlTableModel
-
@VRonin SQLite does since some times already and Qt 5.10 should have proper support for that. Until then, positional is the safest way as you wrote.
-
@SGaist
I redid the query like this:(ID,Name,Pic,What,Material,Color,Description,AdoptDate,Signed,History,Age,Notes)" "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); querys.bindValue (0, sIDReview); querys.bindValue (1, nameReview); querys.bindValue (2, fileByteArray); querys.bindValue (3, whatReview); querys.bindValue (4, materialReview); querys.bindValue (5, colorReview); querys.bindValue (6, descriptionReview); querys.bindValue (7, adoptDateStr); querys.bindValue (8, SignedbyReview); querys.bindValue (9, historyReview); querys.bindValue (10, ageReview); querys.bindValue (11, notesReview); bool result = querys.exec ();
It gave me this error :
Error inserting into the main db! QSqlError("", "Parameter count mismatch", "")
External WM_DESTROY received for QWidgetWindow(0x24d75c10, name="ReviewWindow") , parent: QWindow(0x0) , transient parent: QWidgetWindow(0x24d7a4b0, name="AdditemWindow")Changing
explicit Review(QWidget* parent = 0);
to
explicit Review(QWidget* parent = Q_NULLPTR);
in review.h
solved everything except the Parameter count mismatch. -
can you try using
addBindValue
instead ofbindValue
? -
@VRonin
I changed as you recommended:querys.prepare ("INSERT INTO Items (ID,Name,Pic,What,Material,Color,Description,AdoptDate,Signed,History,Age,Notes)" "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); querys.addBindValue (sIDReview); querys.addBindValue (nameReview); querys.addBindValue (fileByteArray); querys.addBindValue (whatReview); querys.addBindValue (materialReview); querys.addBindValue (colorReview); querys.addBindValue (descriptionReview); querys.addBindValue (adoptDateStr); querys.addBindValue (SignedbyReview); querys.addBindValue (historyReview); querys.addBindValue (ageReview); querys.addBindValue (notesReview); bool result = querys.exec ();
Still the same error message.
-
Do you have anything null/invalid that you pass to addBindValue ?
-
@SGaist
Nothing invalid, but I had a bunch of blank text fields which I'm sure translate into null. -
@SGaist
Even when I fill out each field I get the same error. -
Don't you have a missing space in your query between the
)
andVALUES
? -
@SGaist
I tried to add space between the " " or ) " but made no difference.
I rebuilt the db and now the images are displayed, but they are all rotated 90° left; no idea why. -
Image debug is not simple... but Base64 is a nice way..
i hope to render you idea...
source on https://github.com/pehohlva/QOASIS/blob/master/test/dkernel/sys/core_htmldriver.cpp
to display RTFD documents + image from mac.
by patrik/* image to html display whitout image link & play in qt4/qt5 */ QByteArray HtmlDriver::pic_encode( QImage im ) { int w=im.width(); int h=im.height(); QByteArray bytes; //// scale if to big if (w > 550 ) { im.scaled(550,550, Qt::KeepAspectRatio); } QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); im.save(&buffer, "PNG"); /// save inside buffer ram if (bytes.size() > 0) { QByteArray blueimag = bytes.toBase64(); QByteArray orderpic("data:image/png;base64,"); orderpic.append(blueimag); return orderpic; /// and insert inside image src= } else { /// if image is brocken 1x1 pixel transparent... but 95% image pass. return QByteArray("data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="); } }