Results 1 to 6 of 6

Thread: Static functions and class members

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Static functions and class members

    There is a problem when multiple errors occur in a row. Normally they should be queued. If I do not make the QMainWindow a parent, only the first error is shown and the others are just dismissed. This has nothing to do with the checkbox for ignoring the same errors in the future, it is just a difference in behaviour regarding the parent selection. I have to admit this does not make that much sense to me.

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

    Default Re: Static functions and class members

    Do you use threads?

  3. #3
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Static functions and class members

    No, I don't use threads. I tried it as a work-around, but got stuck there too. Also seemed to be too complicated for what I need.

    Here is some code to illustrate things :

    .h file :

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "OctoObject.h"
    6.  
    7. class OctoNormalise;
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    15. ~MainWindow();
    16.  
    17. private:
    18. OctoNormalise* normalise;
    19.  
    20. //All static objects to allow for the use of the static callback function
    21. static QErrorMessage* errorMessage;
    22. static void _stdcall errorHandler(OctoObject::error_code error);
    23.  
    24. };
    25.  
    26. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    .cpp file :

    Qt Code:
    1. #include "QTGUI"
    2. #include "mainwindow.h"
    3. #include "OctoNormalise.h"
    4.  
    5. QErrorMessage* MainWindow::errorMessage = 0;
    6.  
    7. MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
    8. : QMainWindow(parent, flags)
    9. {
    10. //Create the QErrorMessage Object
    11. errorMessage = new QErrorMessage;
    12.  
    13. //Set the error handler
    14. OctoObject::setErrorHandler(&MainWindow::errorHandler);
    15.  
    16. //Create an object from the SDK as a test (this force the generation of several errors the way it is done now)
    17. normalise = new OctoNormalise;
    18.  
    19. }
    20.  
    21. void __stdcall MainWindow::errorHandler(OctoObject::error_code error)
    22. {
    23. //Select the dialog text based on the error coming from the SDK
    24.  
    25. switch (error)
    26. {
    27. case OctoObject::HaspErr : errorMessage->showMessage(QString("No valid HASP key available")); break;
    28. case OctoObject::FileOpenErr : errorMessage->showMessage(QString("File could not be found/opened")); break;
    29. // ...
    30. }
    31. }
    32.  
    33. MainWindow::~MainWindow()
    34. {
    35. //Delete all used objects
    36. delete normalise;
    37. delete errorMessage;
    38.  
    39. //Resets the error handler to a dummy function (not actually NULL, this is implemented in the SDK to be handled safely)
    40. OctoObject::setErrorHandler(NULL);
    41.  
    42. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Static functions and class members

    Hmm, I noticed there are strange things going on with the callback pointer, it seems to change. Maybe this is not entirely Qt related, I am going to contact the supplier.

    Off course, this does not change the fact it is a pity the static function can not access members of the class. Any suggestions there remain interesting .

Similar Threads

  1. Custom Event or Queued Connection ?
    By vishwanath in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2006, 13:55

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.