Results 1 to 2 of 2

Thread: Pass a QIcon as an argument to a function

  1. #1
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Pass a QIcon as an argument to a function

    Hi
    How do i pass a QIcon to a function in other class, so that it uses the icon, lets say, in a QPushButton.
    I trie something like this:
    Qt Code:
    1. void Form::setMyIcon(QIcon x)
    2. {
    3. ui->pushButton->setIcon(x);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Is this the way or just a wrong approach?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pass a QIcon as an argument to a function

    Quote Originally Posted by aguleo View Post
    Is this the way or just a wrong approach?
    Looks good. Ideally use the same argument signature as QAbstractButton::setIcon, i.e.

    Qt Code:
    1. void Form::setMyIcon(const QIcon &x)
    To copy to clipboard, switch view to plain text mode 

    But your version works as well.

    Cheers,
    _

Similar Threads

  1. pass member function as argument int template function
    By bibhukalyana in forum General Programming
    Replies: 1
    Last Post: 12th March 2013, 07:05
  2. How to pass an argument to evaluateJavaScript function?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 5
    Last Post: 5th January 2013, 09:45
  3. Replies: 3
    Last Post: 21st May 2011, 14:58
  4. Replies: 5
    Last Post: 20th September 2010, 10:30
  5. Replies: 3
    Last Post: 28th February 2010, 08:10

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.