Results 1 to 7 of 7

Thread: What's wrong in this connection?

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default What's wrong in this connection?

    Hi, I'm trying to connect one signal with one slot but I can't find the problem. Where can it be?


    Qt Code:
    1. QMenu* menu = new QMenu();
    2.  
    3. QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
    4. while (it != miHashTable.constEnd())
    5. {
    6. QString nameSubmenu = it.value();
    7. QAction* action = menu->addAction(nameSubmenu );
    8.  
    9. bool pleaseWork = QObject::connect(action, SIGNAL(QAction::triggered(bool)), action, SLOT(setVisible(bool)));
    10. it++;
    11. }
    To copy to clipboard, switch view to plain text mode 


    "pleaseWork" is always false (I use to set the breakpoint at it++), I've tried with this slot (it should work because it's a QT default slot...) and with functions declared as private, other declared as private slot, with or without parameters... any hint?

    thanks!

  2. #2
    Join Date
    Jun 2008
    Location
    Germany/Belarus/Sweden
    Posts
    53
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: What's wrong in this connection?

    void QAction::triggered ( bool checked = false ) [signal]

    This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger() was called. Notably, it is not emitted when setChecked() or toggle() is called.

    If the action is checkable, checked is true if the action is checked, or false if the action is unchecked.
    visible : bool

    This property holds whether the action can be seen (e.g. in menus and toolbars).

    If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.

    Actions which are not visible are not grayed out; they do not appear at all.

    By default, this property is true (actions are visible).
    try this:
    Qt Code:
    1. bool pleaseWork = QObject::connect(action, SIGNAL(triggered(bool)), action, SLOT(setVisible(bool)));
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: What's wrong in this connection?

    Drop the "QAction::" part in signal signature.
    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.


  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: What's wrong in this connection?

    now seems to work... it's strange, I added that QAction when it wasn't working and I was searching the problem; well, now I just need your help to discover why my cutomized slot does not work... :S


    Qt Code:
    1. QMenu* menu = new QMenu();
    2.  
    3. QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
    4. while (it != miHashTable.constEnd())
    5. {
    6. QString nameSubmenu = it.value();
    7. QAction* action = menu->addAction(nameSubmenu );
    8.  
    9. bool pleaseWork = QObject::connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStatus(bool)));
    10. it++;
    11. }
    To copy to clipboard, switch view to plain text mode 

    header file (after public and private, in other projects it worked fine, and I've tried as private and public and public slots and private slots)
    Qt Code:
    1. private slots:
    2. void changeStatus(bool a);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CIAguja::changeStatus(bool a)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    thanks again!

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: What's wrong in this connection?

    did you had an Q_OBJECT macro in your class defination?

  6. #6
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: What's wrong in this connection?

    yes, I have it.

  7. #7
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: What's wrong in this connection?

    .
    ..
    ...

    well, so many hours trying and trying and trying and, in the end, it's true, I didn't have the macro in that, and only that (because I use a template!) new header file... working the fridays-afternoon, and having to repair the code the mondays-morning is definitly bad for the health of the code :S
    Last edited by jano_alex_es; 14th September 2009 at 10:38. Reason: grammar mistakes

Similar Threads

  1. validate database connection
    By hoshy in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2009, 14:14
  2. wrong connection? program crashes altough it compiles
    By cbarmpar in forum Qt Programming
    Replies: 7
    Last Post: 30th September 2008, 13:48
  3. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 09:42
  4. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22
  5. What's wrong with this connection??
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2006, 20:44

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.