Results 1 to 12 of 12

Thread: QT Desktop Screenshot not working

  1. #1
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QT Desktop Screenshot not working

    I am working on a QT program, its my first QT C++ app and I am using MSVS 2008 as my IDE.

    My app runs great when I debug in Release mode and it takes a screenshot and puts it in the apps DIR. Now I want to pass it to a friend to make sure it works on Vista. So I go to test it on my comp outside of the IDE by just clicking the generated exe in my Apps Release folder and it starts up and all the code is working great with no errors except the screenshots. It wasnt generating errors but it also wasn't taking the screenshots even though I know that section of code is being hit.

    I tried to switch from an implicit app path for the scrrenshot file, to an explicit C:\test.jpeg and it works again within the IDE and not outside of it. Im at a loss right now for why this would happen. I also deleted my Release folder and recompiling to make sure it was refreshing all the files.

    Qt Code:
    1. #include "thewge.h"
    2. #include "ui_thewge.h"
    3. #include <QtGui/QApplication>
    4. #include <QSignalMapper>
    5. #include <QPushButton>
    6. #include <QWidget>
    7. #include <QTimer>
    8. #include <QDesktopWidget>
    9. #include <QPixmap>
    10. #include <windows.h>
    11. #include <iostream>
    12. #include "md5.h"
    13. #include "mysql++.h"
    14.  
    15. TheWGE::TheWGE(QWidget *parent, Qt::WFlags flags)
    16. : QMainWindow(parent, flags)
    17. {
    18.  
    19. ui.setupUi(this);
    20.  
    21. QObject::connect(ui.LoginBtn, SIGNAL(clicked()), this, SLOT(login()));
    22.  
    23. }
    24.  
    25. TheWGE::~TheWGE()
    26. {
    27. //ui.usrLineEdit->clear();
    28. //ui.pwdLineEdit->clear();
    29. }
    30.  
    31. void TheWGE::login()
    32. {
    33.  
    34. if (ui.usrLineEdit->text().trimmed().isEmpty() )
    35. {
    36. ui.usrLineEdit->setFocus();
    37. }
    38. else if (ui.pwdLineEdit->text().trimmed().isEmpty() )
    39. {
    40. ui.pwdLineEdit->setFocus();
    41. }
    42.  
    43. mysqlpp::Connection con(false);
    44.  
    45. if (!con.connect("db", "host", "user", "pass"))
    46. {
    47. qApp->exit(0);
    48.  
    49. }
    50.  
    51. // Query Mysql
    52. mysqlpp::Query query = con.query();
    53.  
    54. QString Qstr1 = ui.usrLineEdit->text();
    55. QString Qstr2 = ui.pwdLineEdit->text();
    56.  
    57. std::string acsUserName2 = Qstr1.toUtf8().data();
    58. std::string acsPassword2 = Qstr2.toUtf8().data();
    59.  
    60.  
    61. query << "SELECT username, password FROM wge_db_user WHERE username = '" << acsUserName2 << "' and password = '" << md5(acsPassword2) << "'";
    62.  
    63. mysqlpp::StoreQueryResult res = query.store();
    64. mysqlpp::Row row;
    65.  
    66.  
    67. if (res.num_rows() > 0)
    68. {
    69. //goodlogin - show new form and hide this form
    70. shootScreen();
    71. QTimer::singleShot (60000, this, SLOT(shootScreen()));
    72. }
    73. else
    74. {
    75. //badlogin- code more here laterrrrrrrrr
    76. qApp->exit(0);
    77.  
    78. }
    79.  
    80. mysqlpp::Connection::thread_end();
    81.  
    82.  
    83. return;
    84. }
    85.  
    86. void TheWGE::shootScreen()
    87. {
    88.  
    89. QPixmap originalPixmap;
    90. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    91.  
    92. originalPixmap.save("test.jpeg");
    93.  
    94. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Desktop Screenshot not working

    The first thing I would check is the return value of originalPixmap.save("test.jpeg");
    Maybe show a message box when it failed.

    When you run a program outside an IDE and it doesn't perform in the same way as in the IDE, then the first thing I check is if the environments are the same. Thus: check if you can actually find the Qt plugins from outside the IDE. The IDE might have an environment to automatically find them, but outside it, they might not be found.

    Therefor, check the saving, as it makes use of such a plugin. If it fails to save, you know it is a problem with your environment, and you need to change some variables. If it doesn't fail, the problem is somewhere else.

  3. #3
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    when you say check the value of originalPixmap.save("test.jpeg");

    I am not sure how to do that or how to catch an error.

    Here is a messagebox I added, I could add the error details there if I knew how. I am going to research more!

    I also want to say that I have the QtGui4.dll visable

    Qt Code:
    1. void TheWGE::shootScreen()
    2. {
    3.  
    4. QPixmap originalPixmap;
    5. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    6.  
    7. originalPixmap.save("test.jpeg");
    8.  
    9. QMessageBox::critical( 0, "TheWGE",
    10. QString("ERROR: ") + errorDetails +
    11. "\n\nApplication will now exit." );
    12.  
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    I came up with this idea. Its also having an error saying that isnull is not a member of Qpixmap

    Qt Code:
    1. if(originalPixmap.isnull())
    2. (
    3. QMessageBox::critical( 0, "TheWGE",
    4. QString("ERROR: ") +
    5. "\n\n Screenshot." );
    6. )
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    try isNull instead of isnull

  6. The following user says thank you to squidge for this useful post:

    harleyskater (26th June 2010)

  7. #6
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    alright, I got the if statement working thx to Juicy.

    It doesn't display the message box, outside or inside the IDE, but if I comment this like out:

    //originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());

    It displays the messagebox. I am still at a loss to why my screenshots would only be working inside the IDE and not from the actual build.exe

    Qt Code:
    1. void TheWGE::shootScreen()
    2. {
    3.  
    4. QPixmap originalPixmap;
    5. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    6.  
    7. if(originalPixmap.isNull())
    8. {
    9. QMessageBox::critical( 0, "TheWGE",
    10. QString("ERROR: ") +
    11. "\n\nApplication will now exit." );
    12. }
    13.  
    14. originalPixmap.save("test.jpeg");
    15.  
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    Here is my Build info also.

    Qt Code:
    1. Build Log Build started: Project: TheWGE, Configuration: Release|Win32
    2. Command Lines Creating temporary file "c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\RSP0000012132280.rsp" with contents
    3. [
    4. /OUT:"c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\TheWGE.exe" /LIBPATH:"C:\Qt\4.6.3\lib" /LIBPATH:"C:\mysql++\vc2005\Release" /LIBPATH:"C:\Program Files\MySQL\MySQL Server 5.1\lib\opt" /MANIFEST /MANIFESTFILE:"Release\TheWGE.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\TheWGE.pdb" /SUBSYSTEM:WINDOWS /DYNAMICBASE:NO qtmain.lib QtCore4.lib QtGui4.lib QtSql4.lib mysqlpp.lib libmysql.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
    5.  
    6. ".\Release\main.obj"
    7.  
    8. ".\Release\md5.obj"
    9.  
    10. ".\Release\thewge.obj"
    11.  
    12. ".\Release\qrc_thewge.obj"
    13.  
    14. ".\Release\moc_thewge.obj"
    15.  
    16. ".\Release\TheWGE.res"
    17. ]
    18. Creating command line "link.exe @"c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\RSP0000012132280.rsp" /NOLOGO /ERRORREPORT:PROMPT"
    19. Creating temporary file "c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\RSP0000022132280.rsp" with contents
    20. [
    21. /outputresource:".\Release\TheWGE.exe;#1" /manifest
    22.  
    23. ".\Release\TheWGE.exe.intermediate.manifest"
    24. ]
    25. Creating command line "mt.exe @"c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\RSP0000022132280.rsp" /nologo"
    26. Creating temporary file "c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\BAT0000032132280.bat" with contents
    27. [
    28. @echo Manifest resource last updated at %TIME% on %DATE% > ".\Release\mt.dep"
    29. ]
    30. Creating command line """c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\BAT0000032132280.bat"""
    31. Output Window Linking...
    32. LINK : c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\TheWGE.exe not found or not built by the last incremental link; performing full link
    33. Embedding manifest...
    34. Results Build log was saved at "file://c:\Documents and Settings\Harleys\My Documents\Visual Studio 2008\Projects\trunk\TheWGE\Release\BuildLog.htm"
    35. TheWGE - 0 error(s), 0 warning(s)
    To copy to clipboard, switch view to plain text mode 
    Last edited by harleyskater; 26th June 2010 at 18:50.

  8. #7
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    I took the next step in trying to solve this, and started a new project for just the screenshot. I built it as simple as possible and I am getting the same result. I am providing a link to my zipped soulution.

    http://www.mediafire.com/?gkkdzkne3nj

  9. #8
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    Development.

    I came across the Example Desktop Screenshot demo from QT and it used a label to display the screenshot, I have used this code to problemsolve if the screenshot is actually being taken, and it is! so the screenshot is working! its just the save command!

    Which means I am at the last step of getting this to work!

    does anyone see anything wrong with this line of code? or have any ideas why this would only be working inside the IDE build.exe?

    originalPixmap.save("test.jpeg");

  10. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Desktop Screenshot not working

    Yes, like I said, plugin problems.
    Your IDE finds the plugins, your exe on its own doesn't.

    Qt Code:
    1. if (!originalPixmap.save("test.jpeg")) {
    2. // Saving didn't work
    3. QMessageBox::warning(this, "Saving error", "Could not save the file. Check the plugins!");
    4. }
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    thanks Tbscope, Do you have an idea how which plugin it might be and how to add it?

  12. #11
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QT Desktop Screenshot not working

    and if you try to place $QTDIR/plugins/imageformats contents (dlls or corresponding dir tree) beside deployed executable ?

  13. The following user says thank you to totem for this useful post:

    harleyskater (27th June 2010)

  14. #12
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Desktop Screenshot not working

    Totem! Hi buddy. I just tried to take the imageformats DIR and copied everything into my release folder containing everything else that is being used with the exe and I am getting the warning message still. I also tried adding the DIR to my additional include directories.


    ANOTHER thing I found is, if I change the MIME type from jpeg to png.... IT WORKS!!!!!!!!!!!!
    Last edited by harleyskater; 27th June 2010 at 06:13.

Similar Threads

  1. Take a screenshot and convert it to PNG but FAST !
    By fitzy in forum Qt Programming
    Replies: 11
    Last Post: 4th November 2009, 08:20
  2. Take a screenshot of a QGraphicsRectItem
    By yazwas in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2009, 13:14
  3. Screenshot
    By graciano in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2009, 16:32
  4. Replies: 5
    Last Post: 31st January 2009, 07:36
  5. Printing Screenshot -> poor quality
    By MarcSchubert in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2007, 10:48

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
  •  
Qt is a trademark of The Qt Company.