Results 1 to 11 of 11

Thread: How to take screenshots and save the binary data in the blob field?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to take screenshots and save the binary data in the blob field?

    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??

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to take screenshots and save the binary data in the blob field?

    Quote Originally Posted by Gokulnathvc View Post
    How to take screenshots
    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?
    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??
    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?

  3. #3
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to take screenshots and save the binary data in the blob field?

    I have tried the following codes:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2.  
    3.  
    4. db = QSqlDatabase::addDatabase("QODBC");
    5. db.setDatabaseName("DRIVER={MYSQL ODBC 3.51 Driver};FIL={MYSQL};DBQ=screengrabber");
    6. db.setHostName("localhost");
    7. db.setConnectOptions("CLIENT_ODBC");
    8. //db.setDatabaseName("screengrabber");
    9. db.setUserName("root");
    10. db.setPassword("1");
    11. ok = db.open();
    12.  
    13. for(;;)
    14. {
    15.  
    16. originalPixmap =QPixmap(); // clear image for low memory situations
    17. // on embedded devices.
    18. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    19.  
    20. QString strfname;
    21. strfname.sprintf("%d",c);
    22. originalPixmap.save("D:\\image"+strfname+".jpeg","jpeg");
    23. c++;
    24. char Data;
    25. QFile file("D:\\image"+strfname+".jpeg");
    26. file.open(QIODevice::ReadOnly);
    27. file.seek(0);
    28. buf=file.read(250000);
    29.  
    30. QSqlQuery query;
    31. query.prepare("INSERT INTO log VALUES('grab_date='2011-04-26 15:55:09',ip_address='172.16.0.51',image=:val');");
    32. query.bindValue ( ":val", buf);
    33.  
    34. QString strquery;
    35.  
    36. strquery = "INSERT INTO log (grab_date,ip_address,image) VALUES ( '";
    37.  
    38. strquery += '2011-04-26 15:55:09';
    39. strquery += "' , '";
    40. strquery += '172.16.0.51';
    41. strquery += "' , ";
    42. strquery += buf;
    43. strquery += " );";
    44.  
    45. //QMessageBox::warning(NULL,"DriveList",strquery,QMessageBox::Ok);
    46.  
    47. QSqlQuery insertQuery( strquery, db);
    48. bool done = insertQuery.exec();}
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to take screenshots and save the binary data in the blob field?

    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:
    Quote Originally Posted by Qt Docs
    Warning: We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream: ...
    Line 26: Are you sure the file opened successfully? You don't bother to check.
    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 32 Shame 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.

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to take screenshots and save the binary data in the blob field?

    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to take screenshots and save the binary data in the blob field?

    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.

  7. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to take screenshots and save the binary data in the blob field?

    How to get the binary data from the QPixmap with out creating the file in the disk??

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to take screenshots and save the binary data in the blob field?

    It's in docs (QPixmap::save).

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to take screenshots and save the binary data in the blob field?

    Quote Originally Posted by Gokulnathvc View Post
    How to get the binary data from the QPixmap with out creating the file in the disk??
    Not only is it in the docs, but I provided you with a link to every page of the docs that you should need to capture this data without using a file on disk. What have you tried?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to take screenshots and save the binary data in the blob field?

    Quote Originally Posted by ChrisW67 View Post
    Lines 16-17: Why construct a null pixmap only to replace it immediately on the next line?
    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 approach Even if no API existed to save it to memory, it would still be funny
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to take screenshots and save the binary data in the blob field?

    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.

Similar Threads

  1. Save binary data into XML file
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2013, 11:16
  2. Replies: 4
    Last Post: 16th June 2011, 14:49
  3. Replies: 21
    Last Post: 6th October 2009, 15:06
  4. Replies: 0
    Last Post: 19th September 2009, 07:07
  5. Replies: 0
    Last Post: 14th September 2009, 11:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.