Results 1 to 12 of 12

Thread: cannot call member function without object

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: cannot call member function without object

    Yes. Here it is:
    main.cpp:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QObject>
    3. #include "widget.h"
    4. #include "qapp.h"
    5.  
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. //QApp *app = qobject_cast<QApp>(qApp);
    10. QApp a(argc, argv);
    11. Widget w;
    12. w.show();
    13.  
    14. QObject::connect(&a,SIGNAL(mouseCoord(int, int, int, int, int)),
    15. &w,SLOT(mouseCoord(int, int, int, int, int)));
    16.  
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    qapp.cpp:
    Qt Code:
    1. extern "C"{
    2. #include "raw_mouse.h"
    3. }
    4. #include "qapp.h"
    5. #include <QDebug>
    6. #include <QAbstractEventDispatcher>
    7. #define WM_INPUT 0x00FF
    8.  
    9. QApp::QApp(int & argc, char ** argv) :
    10. QApplication(argc,argv)
    11. {
    12. qDebug() << init_raw_mouse(1, 0, 1);
    13. qDebug() << raw_mouse_count();
    14. QAbstractEventDispatcher::instance(0)->setEventFilter(eventFilter);
    15.  
    16.  
    17.  
    18. }
    19.  
    20.  
    21. bool QApp::eventFilter(void *msg)
    22. {
    23. MSG *mess;
    24.  
    25. mess = (MSG*)msg;
    26. //qDebug() << mess->message;
    27. switch(mess->message){
    28. case WM_INPUT:
    29. {
    30. add_to_raw_mouse_x_and_y((HANDLE)mess->lParam);
    31. for (int i = 0; i < raw_mouse_count(); i++){
    32. emit mouseCoord(get_raw_mouse_x_delta(i), get_raw_mouse_y_delta(i),
    33. is_raw_mouse_button_pressed(i, 0), is_raw_mouse_button_pressed(i, 1), is_raw_mouse_button_pressed(i, 2));
    34. }
    35.  
    36. }
    37. return true;
    38. }
    39. return false;
    40. }
    To copy to clipboard, switch view to plain text mode 

    app.h:
    Qt Code:
    1. #ifndef QAPP_H
    2. #define QAPP_H
    3.  
    4. #include <QApplication>
    5.  
    6. class QApp : public QApplication
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit QApp(int & argc, char ** argv );
    11. //bool winEventFilter(MSG *message, long *result);
    12. static bool eventFilter(void *msg);
    13. private:
    14.  
    15. signals:
    16. void mouseCoord(int x, int y, int btn1, int btn2, int btn3);
    17.  
    18. public slots:
    19.  
    20. };
    21.  
    22. #endif // QAPP_H
    To copy to clipboard, switch view to plain text mode 

  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: cannot call member function without object

    Why not do it this way?

    Qt Code:
    1. bool myInputEventFilter(void*);
    2.  
    3. class QApp : public QApplication {
    4. Q_OBJECT
    5. friend bool myInputEventFilter(void *);
    6. public:
    7. QApp(int argc, char **argv) : QApplication(argc, argv){
    8. init_raw_mouse(1, 0, 1);
    9. QAbstractEventDispatcher::instance(0)->setEventFilter(myInputEventFilter);
    10. }
    11. signals:
    12. void mouseCoord(int x, int y, int btn1, int btn2, int btn3);
    13. };
    14.  
    15. // the following function may probably be made static so that it doesn't pollute the namespace
    16. bool myInputEventFilter(void *msg) {
    17. MSG *mess = (MSG*)msg;
    18. QApp *app = (QApp*)qApp;
    19. switch(mess->message){
    20. case WM_INPUT:
    21. {
    22. add_to_raw_mouse_x_and_y((HANDLE)mess->lParam);
    23. for (int i = 0; i < raw_mouse_count(); i++){
    24. emit app->mouseCoord(get_raw_mouse_x_delta(i), get_raw_mouse_y_delta(i),
    25. is_raw_mouse_button_pressed(i, 0), is_raw_mouse_button_pressed(i, 1), is_raw_mouse_button_pressed(i, 2));
    26. }
    27.  
    28. }
    29. return true;
    30. }
    31. return false;
    32. }
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: cannot call member function without object

    Great! Working perfectly now. Thanks Wysota.
    What do you mean with "pollute the namespace"?

  4. #4
    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: cannot call member function without object

    Quote Originally Posted by been_1990 View Post
    What do you mean with "pollute the namespace"?
    Try defining (in a different cpp file) a function called myInputEventFilter and taking a void* as input and you'll see for yourself.
    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.


Similar Threads

  1. Replies: 1
    Last Post: 8th October 2010, 11:38
  2. Replies: 2
    Last Post: 7th July 2009, 17:44
  3. Replies: 10
    Last Post: 29th May 2009, 09:06
  4. How to call the C++ member function from the JScript
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2008, 10:13
  5. Cannot call function without object
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 11th June 2007, 14: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.