Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QState::addTransition method gives error when called by non-pointer type
Forum Updated to NodeBB v4.3 + New Features

QState::addTransition method gives error when called by non-pointer type

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 137 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BosGemilerB Offline
    BosGemilerB Offline
    BosGemiler
    wrote on last edited by
    #1

    Hello everyone,
    I faced with an unexpected error. And I couldn't understand what causes this error.

    I created one button and want to transmit from phase-1 to phase-2 when button is clicked.

    QStateMachine machine;
    QState phase_1_st;
    QState phase_2_st;
    machine.addState(&phase_1_st);
    machine.addState(&phase_2_st);
    
    phase_1_st.addTransition(ui->btn_change, &QPushButton::clicked, phase_2_st); // ERROR: function declaration is not matched 
    

    When I used QState variable in pointer type, then problem is resolved.

    QStateMachine machine;
    QState *phase_1_st = new QState();
    QState *phase_2_st = new QState();
    machine.addState(phase_1_st);
    machine.addState(phase_2_st);
    
    phase_1_st->addTransition(ui->btn_change, &QPushButton::clicked, phase_2_st);
    

    Maybe , it is related with C++ rules, no even Qt.
    I would like to learn this mystery :)
    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Look at the function signature, it takes a pointer to an object and not an object. If you want to keep the object on the stack, you still have to pass its address.

      Nothing Qt here, just plain C++.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • BosGemilerB BosGemiler has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved