How to take screenshots and save the binary data in the blob field of the MYSQL Database??
How to connect to the MYSQL database ,tables and save the long binary data into the blob field of the database??
How to take screenshots and save the binary data in the blob field of the MYSQL Database??
How to connect to the MYSQL database ,tables and save the long binary data into the blob field of the database??
Back here you claim to already be doing this... guess not. What have you tried? Where else have you looked for help? Have you looked in the Qt Docs? Have you looked at open source projects that do this sort of thing?
Which parts or parts of the answers to the other times you have asked related questions are you having difficulty with? What have you tried?and save the binary data in the blob field of the MYSQL Database??
How to connect to the MYSQL database ,tables and save the long binary data into the blob field of the database??
I have tried the following codes:
Qt Code:
db.setDatabaseName("DRIVER={MYSQL ODBC 3.51 Driver};FIL={MYSQL};DBQ=screengrabber"); db.setHostName("localhost"); db.setConnectOptions("CLIENT_ODBC"); //db.setDatabaseName("screengrabber"); db.setUserName("root"); db.setPassword("1"); ok = db.open(); for(;;) { // on embedded devices. QString strfname; strfname.sprintf("%d",c); originalPixmap.save("D:\\image"+strfname+".jpeg","jpeg"); c++; char Data; file.seek(0); QByteArray buf; buf=file.read(250000); QSqlQuery query; query.prepare("INSERT INTO log VALUES('grab_date='2011-04-26 15:55:09',ip_address='172.16.0.51',image=:val');"); query.bindValue ( ":val", buf); QString strquery; strquery = "INSERT INTO log (grab_date,ip_address,image) VALUES ( '"; strquery += '2011-04-26 15:55:09'; strquery += "' , '"; strquery += '172.16.0.51'; strquery += "' , "; strquery += buf; strquery += " );"; //QMessageBox::warning(NULL,"DriveList",strquery,QMessageBox::Ok); bool done = insertQuery.exec();}To copy to clipboard, switch view to plain text mode
Lines 1-10: you should be using the native MySQL driver, so I guess you didn't manage to build that. This will do but isn't ideal.
Lines 16-17: Why construct a null pixmap only to replace it immediately on the next line?
Line 20-29: If you don't want the data in a file on disk why save it to a file?
Line 21:Line 26: Are you sure the file opened successfully? You don't bother to check.Originally Posted by Qt Docs
Line 27: Unnecessary as this is the default position in a newly opened file.
Line 29: Fails to give you the whole file if the file is large than 250000 bytes.
Line 32: This is not valid SQL as was pointed out the last time you asked. You said you tried the corrected version provided... I guess you didn't bother. Get into the habit of checking return codes. QSqlQuery::prepare() returns false on failure. When it does so QSqlQuery::lastError() is useful. Get into the habit of using the error message the system provides.
Line 34: I guess you didn't want to execute the query you prepared at 32Shame really because it is close to working.
Lines 37-44: Building queries like this is clumsy, error prone, dangerous and, in the case of binary data, not useful. Go back to line 32.
Line 49: Have you checked "done"?
Last edited by ChrisW67; 29th June 2011 at 09:34.
I am getting in:
line :11 'ok' as true;
line 26: file is opened successfully.
line 27: removed
line 29: size will be less than that.
line 32: I dont know about this query, i didnt use this also. So i need more guidance towards this issue.
line 49: 'done' is false.
Line 26: Good, but irrelevant because you don't want the data in a file anyway. How else can you QPixmap::save()? What is a QIODevice and how might you use a QBuffer?
Line 32: read the thread I linked to. The answer is there. You cannot use an SQL database without learning some (very basic) SQL.
Line 49: Of course it is. The SQL is invalid and there is no way to fix it with arbitrary binary data. That is one of the reasons you use the bind variable approach from line 32.
How to get the binary data from the QPixmap with out creating the file in the disk??
It's in docs (QPixmap::save).
I think it might make sense. If you are low on memory and you execute this method more than once then upon entering into the method a large pixmap might still be using a significant amount of memory. Creating a new one and assigning it to the same variable first creates the pixmap (which requires resources) and only then assigns it to the original variable which clears the old pixmap. So at some point in time you have two pixmaps and can run out of memory.
Which doesn't change a fact that saving a file just to read it back is kind of a funny approachEven if no API existed to save it to memory, it would still be funny
![]()
Fair call. I misread it as creating the QPixmap object inside the loop, which would ensure it was destroyed at the bottom of each trip through the for() loop.
Bookmarks