Results 1 to 12 of 12

Thread: how to connect an openfile signal to a widget slot?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to connect an openfile signal to a widget slot?

    @stampede: it worked like a charm!!
    thank you very much..I always really confused with the usage of "this"
    What is the actual difference between the two lines??
    Qt Code:
    1. this->mainPlot->plotMainCurve(file);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. widget->mainPlot->plotMainCurve(fileName);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to connect an openfile signal to a widget slot?

    "this" is a pointer to the object which "posesses" the current method.

    the difference is that the second line "widget->mainPlot..." works only if "mainPlot" is public. That's why I recommended to create a getter. The following would have worked too:
    Qt Code:
    1. widget->Get2DPlot()->plotMainCurve(file)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how to connect an openfile signal to a widget slot?

    What is the actual difference between the two lines??
    You use "this" keyword from class methods when you refer to actualy used class instance ( the object that "calls" the method or access the class member ).
    Of course you have access to all members of the class in this case.

    Here
    widget->mainPlot->plotMainCurve(fileName);
    you use some object "widget" to call the method. You can access only public members of the "widget" object ( unless you are a friend of a class )

    This basic knowledge is mandatory in C++ programming, I really recommend some reading before going into qt programming ( you can find some useful info here: http://www.qtcentre.org/threads/29-W...ourite-C-books )

Similar Threads

  1. Replies: 2
    Last Post: 15th September 2010, 00:54
  2. Can't connect a signal to a slot
    By cejohnsonsr in forum Newbie
    Replies: 5
    Last Post: 26th August 2010, 20:42
  3. How to connect signal/slot in QItemEditorFactory?
    By yyalli in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2010, 14:56
  4. problem connect signal - slot
    By jaca in forum Newbie
    Replies: 13
    Last Post: 9th March 2010, 19:38
  5. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.