Results 1 to 15 of 15

Thread: Unbelievable error!

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Unbelievable error!

    I have 2 differents functions/slots (in the same class) in which I emit the same signal and...one of them works, that is the slot associated to this signal is executed, and the second one does not! I have made a copy-paste of the slot code so as to be sure that it was exactly the same and still this inbelievable error! To sum up my code:
    Qt Code:
    1. class A
    2. {
    3. public slots:
    4. void sl(<some data type>);
    5. };
    6. class B
    7. {
    8. signals:
    9. void si(<some data type>);
    10. public slots:
    11. void sl1() {emit si(<some data type>);};
    12. void sl2() {emit si(<some data type>);};
    13. };
    14. main()
    15. {
    16. A a;
    17. B b;
    18. QObject::connect(B, SIGNAL(si(<some data type>)), A, SLOT(sl(<some data type>)));
    19. ...
    20. }
    To copy to clipboard, switch view to plain text mode 
    Of course <some data type> is identical everywhere.
    Did anybody face a so strange story?

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

    Default Re: Unbelievable error!

    No. But if you show us the actual code, maybe we can see the problem. Also look at the terminal while running your application if Qt spits out some warning messages about invalid connections.

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by wysota View Post
    No. But if you show us the actual code, maybe we can see the problem. Also look at the terminal while running your application if Qt spits out some warning messages about invalid connections.
    Not that easy because my code is huge! But I tried to extract the relevant lines:
    Qt Code:
    1. class Simulator : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public slots:
    6. void SetPositions(std::vector<std::vector<std::vector<double> > > positions);
    7. }
    8.  
    9. void
    10. Simulator::SetPositions(std::vector<std::vector<std::vector<double> > > positions)
    11. {
    12. this->Print("%d %d %d (%lf,%lf)", positions.size(), positions[0].size(), positions[0][0].size(), positions[0][0][0], positions[0][0][1]);
    13. }
    14.  
    15. class Display : public QLabel
    16. {
    17. Q_OBJECT
    18.  
    19. signals:
    20. void PositionsHaveChanged(std::vector<std::vector<std::vector<double> > > positions);
    21.  
    22. public slots:
    23. void Clear2();
    24. void mousePressEvent(QMouseEvent *);
    25. }
    26.  
    27. void
    28. Display::Clear2()
    29. {
    30. this->Print("-> Clear2()");
    31. std::vector<std::vector<std::vector<double> > > pos;
    32. std::vector<double> v(2);
    33. v[0] = v[1] = 1.0;
    34. std::vector<std::vector<double> > p;
    35. p.push_back(v);
    36. pos.push_back(p);
    37. this->Print("%d %d %d (%lf,%lf)", pos.size(), pos[0].size(), pos[0][0].size(), pos[0][0][0], pos[0][0][1]);
    38. emit PositionsHaveChanged(pos);
    39. this->Print("<- Clear2()");
    40. }
    41.  
    42. void
    43. Display::mousePressEvent(QMouseEvent *e)
    44. {
    45. this->Print("-> mousePressEvent()");
    46. std::vector<std::vector<std::vector<double> > > pos;
    47. std::vector<double> v(2);
    48. v[0] = v[1] = 1.0;
    49. std::vector<std::vector<double> > p;
    50. p.push_back(v);
    51. pos.push_back(p);
    52. this->Print("%d %d %d (%lf,%lf)", pos.size(), pos[0].size(), pos[0][0].size(), pos[0][0][0], pos[0][0][1]);
    53. emit PositionsHaveChanged(pos);
    54. this->Print("<- mousePressEvent()");
    55. }
    56.  
    57.  
    58. Display *display = new Display();
    59. Simulator *sim = new Simulator();
    60. QObject::connect(display, SIGNAL(PositionsHaveChanged(std::vector<std::vector<std::vector<double> > >)),
    61. sim, SLOT(SetPositions(std::vector<std::vector<std::vector<double> > >)));
    62.  
    63.  
    64. b = new QPushButton(QString::fromLocal8Bit("Clear"));
    65. QObject::connect(b, SIGNAL(clicked()), display, SLOT(Clear2()));
    To copy to clipboard, switch view to plain text mode 

    If I clic in the image (the label contains a pixmap) it works but if I clic on the button it does not:

    Qt Code:
    1. Display: -> mousePressEvent()
    2. Display: 1 1 2 (1.000000,1.000000)
    3. Simulator: 1 1 2 (1.000000,1.000000)
    4. Display: <- mousePressEvent()
    5.  
    6. Display: -> Clear2()
    7. Display: 1 1 2 (1.000000,1.000000)
    8. Display: <- Clear2()
    To copy to clipboard, switch view to plain text mode 

    No error message from Qt.

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

    Default Re: Unbelievable error!

    Hmm.. the output you pasted seems to indicate that Clear2() is called. What is the output you'd expect?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unbelievable error!

    When does Simulator print its line?

  6. #6
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by wysota View Post
    Hmm.. the output you pasted seems to indicate that Clear2() is called. What is the output you'd expect?
    I would expect to obtain exactly the same output since both slots (mousePressEvent and Clear2) have the same code! But obviously Simulator::SetPositions() is called when (mousePressEvent emits the PositionsHaveChanged signal and not called when the signal is emitted by Clear2. This is my problem.

  7. #7
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by jacek View Post
    When does Simulator print its line?
    in slot SetPositions(), Print() method is basically a printf that adds the name of the class on the left.

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

    Default Re: Unbelievable error!

    So which slot is not called? SetPositions? Did you remember to register a meta-type for your custom argument types?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unbelievable error!

    Quote Originally Posted by Caius Aérobus View Post
    in slot SetPositions(), Print() method is basically a printf that adds the name of the class on the left.
    What happens if you place it in the first line of that slot?

  10. #10
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by jacek View Post
    What happens if you place it in the first line of that slot?
    but that slot has a single line:

    Qt Code:
    1. void
    2. Simulator::SetPositions(std::vector<std::vector<std::vector<double> > > positions)
    3. {
    4. this->Print("%d %d %d (%lf,%lf)", positions.size(), positions[0].size(), positions[0][0].size(), positions[0][0][0], positions[0][0][1]);
    5. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by wysota View Post
    So which slot is not called? SetPositions? Did you remember to register a meta-type for your custom argument types?

    yes SetPositions(), which receives the emit PositionsHaveChanged() signal when it is emitted by mousePressEvent() but does not receive it when emitted by Clear2().

    meta-type? euhhhh actually no but:
    - I had in mind that this was related to QVariant class in order to make unions of a limited list of types...
    - anyway it does not explain why it works for mousePressEvent() and not for Clear2() (it should either work or not work for both, shouldn't it?)

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Unbelievable error!

    I can't see in your code a connect statement that connects to the mousePressEvent() slot.
    Never mind I see now what you meant.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unbelievable error!

    Quote Originally Posted by high_flyer View Post
    I can't see in your code a connect statement that connects to the mousePressEvent() slot.
    Never mind I see now what you meant.
    The mousePressEvent() is "natively" connected to the mouse :-) through the QLabel class, so no need to connect it anymore.

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Unbelievable error!

    I am not sure what do you mean... after all.
    I think you might (if I am getting right what I see in your code and what you say) be confusing the mousePressEvent() *event handler* and the mousePressEvent() slot you have overridden in your QLabel subclass!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: Unbelievable error!

    Quote Originally Posted by Caius Aérobus View Post
    yes SetPositions(), which receives the emit PositionsHaveChanged() signal when it is emitted by mousePressEvent() but does not receive it when emitted by Clear2().
    Are you sure the signal indeed gets emited? And don't ask me why shouldn't it be emitted. Just connect some other slot to it and find out.

Similar Threads

  1. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.