Results 1 to 7 of 7

Thread: method creation

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question method creation

    Hi to all!

    I am developing an application that will have a lot of menus. Now, I've prepared following code snippet:

    Qt Code:
    1. m_pDataSourceAction=new QAction(tr("&Data source ..."), this);
    2. Q_CHECK_PTR(m_pDataSourceAction);
    3. m_pDataSourceAction->setShortcut(tr("Ctrl+D"));
    4. m_pDataSourceAction->setStatusTip(tr("Selects data source"));
    5. connect(m_pDataSourceAction, SIGNAL(triggered()), this, SLOT(dataSourceSelection()));
    To copy to clipboard, switch view to plain text mode 

    How do I transform this code snipper into an flexible method - method with paramateres ActionText, ShortcutCombo, StatusTipText, SourceSignal, TargetSlot. Now, method should return pointer to QAction, I am aware of that. But how do I declare signal and slot as a parameter of method?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: method creation

    First of all, I don't think you need to pass the signal. Probably you will always use triggered.

    But anyway, you can do this:
    Qt Code:
    1. QAction* MyClass::createAction( const QString& text, const QString &shortcut, const char * signal, const char* slot, const QString statusTip )
    2. {
    3. QAction* pAction=new QAction(tr( text ), this);
    4. Q_CHECK_PTR(pAction);
    5. pAction->setShortcut(tr( shortcut ));
    6. pAction->setStatusTip(tr( statusTip ));
    7. connect(pAction, signal , this, slot );
    8. return pAction;
    9. }
    To copy to clipboard, switch view to plain text mode 
    When you call createAction, for signal you pass something like:
    SIGNAL( triggered() );
    and for slot:
    SLOT( dataSourceSelection() ).

    Qt Code:
    1. createAction( "Data source", "CTRL+D", SIGNAL( triggered() ), SLOT( dataSourceSelection() ), "status tip..." );
    To copy to clipboard, switch view to plain text mode 
    It will work.

    By the way, I think you should have posted at least in the Newbie section.

    Regards
    Last edited by marcel; 30th May 2007 at 08:20.

  3. The following user says thank you to marcel for this useful post:

    MarkoSan (30th May 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Talking Re: method creation

    Ok, sorry! But i just did not know how to integrate signal and slot as parameters ...
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: method creation

    Hey, no problem for me.
    I'm sure Wysota will move it .

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: method creation

    Ok, should I pm him to move it?
    Qt 5.3 Opensource & Creator 3.1.2

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

    Default Re: method creation

    Quote Originally Posted by marcel View Post
    I'm sure Wysota will move it .
    Why me? I'm not the only one who can moderate threads here, you know...

    Quote Originally Posted by MarkoSan View Post
    Ok, should I pm him to move it?
    No need for that. I just got up and started my cruise around the forum

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: method creation

    Why me? I'm not the only one who can moderate threads here, you know...
    Well, you and Jacek.
    As for the other moderators, I haven't seen them around that much.

Similar Threads

  1. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:05
  2. Calling Recursivly loading function in Run() method of QThread
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:42
  3. Replies: 2
    Last Post: 27th March 2007, 13:09
  4. Replies: 4
    Last Post: 10th March 2007, 19:01
  5. variable in method not initialized?!
    By frosch in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2006, 15:09

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.