Results 1 to 4 of 4

Thread: Guarded transition depending on an object (not a type)

  1. #1

    Default Guarded transition depending on an object (not a type)

    Hello all,

    I'm trying to implement a Guarded Transition for a QStateMachine following this example:
    Qt Code:
    1. class CheckedTransition : public QSignalTransition
    2. {
    3. public:
    4. CheckedTransition(QCheckBox *check)
    5. : QSignalTransition(check, SIGNAL(stateChanged(int))) {}
    6. protected:
    7. bool eventTest(QEvent *e) {
    8. if (!QSignalTransition::eventTest(e))
    9. return false;
    10. QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e);
    11. return (se->arguments().at(0).toInt() == Qt::Checked);
    12. }
    13. };
    14.  
    15. ...
    16.  
    17. QCheckBox *check = new QCheckBox();
    18. check->setTristate(true);
    19.  
    20. QState *s1 = new QState();
    21. QState *s2 = new QState();
    22. CheckedTransition *t1 = new CheckedTransition(check);
    23. t1->setTargetState(s2);
    24. s1->addTransition(t1);
    To copy to clipboard, switch view to plain text mode 

    However, in my case, instead of the signal stateChanged(int) with only an int argument, I have a signal with two arguments: an object and an enum type, and depending on the state of the object the eventTest will return true or false. This is my signal:

    Qt Code:
    1. void newMessage(Message, System);
    To copy to clipboard, switch view to plain text mode 

    System is an enum type so I can access it as if it were an int value, but Message is a class... and I do not know how to access to this argument through the SignalEvent instance. So, my problem is exactly in this expression:

    Qt Code:
    1. se->arguments().at(0).toInt()
    To copy to clipboard, switch view to plain text mode 

    I have tried to cast the QVariant object to a Message instance but it generated an error. Does anyone know any solution? Is it possible to do what I want?

    Thanks in advance,

  2. #2
    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: Guarded transition depending on an object (not a type)

    Does Message inherit QObject? Is it registered with QVariant?
    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

    Default Re: Guarded transition depending on an object (not a type)

    No, Message does not inherit QObject neither it is registered with QVariant. Do I have to do these things to achieve what I want? Can you outline me a little more those two points?

    Thanks,

  4. #4
    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: Guarded transition depending on an object (not a type)

    If you want to get this kind of object as a stored argument then it has to be registered with QVariant.
    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. Block object type QGraphicsView
    By Mariusz_1990 in forum Newbie
    Replies: 0
    Last Post: 24th June 2013, 08:45
  2. Replies: 1
    Last Post: 15th March 2012, 15:34
  3. Querying object type using itemAt
    By ajb in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 16:35
  4. [solved] Which object type is QObject::sender()?
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 8th May 2009, 21:03
  5. Getting type of object
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 29th November 2007, 14:38

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.