Results 1 to 7 of 7

Thread: QAction, triggered signal dont call a slot

  1. #1
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QAction, triggered signal dont call a slot

    Hello,
    I have QMainWindow and i created a QMenuBar added QMenu in it with actions that are connected with some slots but when i run appliacation and want to use some options from menu the slot is not called, i dont know where is a problem.

    Here is main window constructor

    Qt Code:
    1. Window::Window(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::Window)
    4. {
    5. ui->centralWidget = new QWidget;
    6. setCentralWidget(ui->centralWidget);
    7. ui->setupUi(this);
    8. ui->render = new Render();
    9.  
    10. ui->menuBar = new QMenuBar;
    11.  
    12. ui->menuAnimacja = new QMenu;
    13.  
    14. createAnimationActions();
    15. ui->menuAnimacja->addAction( ui->actionStart );
    16. ui->menuAnimacja->addAction( ui->actionStop );
    17. ui->menuBar->addMenu( ui->menuAnimacja );
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    and here i am creating actions

    Qt Code:
    1. void Window::createAnimationActions()
    2. {
    3. ui->actionStart = new QAction(this);
    4. connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(startAnimation()));
    5.  
    6. ui->actionStop = new QAction(this);
    7. connect(ui->actionStop, SIGNAL(triggered()), this, SLOT(stopAnimation()));
    8. }
    To copy to clipboard, switch view to plain text mode 

  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: QAction, triggered signal dont call a slot

    Do you get any warnings at the console?
    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 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QAction, triggered signal dont call a slot

    No warns at all

  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: QAction, triggered signal dont call a slot

    Could you show us the declaration of your Window class?
    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.


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QAction, triggered signal dont call a slot

    Qt Code:
    1. ui->actionStart = new QAction(this);
    To copy to clipboard, switch view to plain text mode 
    why are you do that? The ui file has already create one. Also setting a central widget in the ctor before calling ui->setupUi() is "nonsens". So most likely you are doing some other things which break the connection. To figure that out, please provide a minimal compilable example reproducing your problem.

    EDIT: Ha! I think because you create a new action you can't trigger it through your created menu anymore.

  6. #6
    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: QAction, triggered signal dont call a slot

    There is more of that. This doesn't make sense too:
    Qt Code:
    1. ui->menuBar->addMenu( ui->menuAnimacja );
    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.


  7. #7
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QAction, triggered signal dont call a slot

    Thanks, guys

Similar Threads

  1. toggled(bool) signal does not call my slot?
    By Asperamanca in forum Newbie
    Replies: 6
    Last Post: 22nd July 2010, 09:54
  2. Signal/slot or direct method call within a class
    By mike_the_tv in forum Newbie
    Replies: 6
    Last Post: 11th March 2010, 18:49
  3. Doxgen call graphs also for signal-slot calls?
    By zavulon in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2008, 15:29
  4. Replies: 3
    Last Post: 19th November 2007, 15:31
  5. Replies: 2
    Last Post: 27th February 2007, 21:06

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.