LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2013, 11:48 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
qt connect a signal to a class function


Hi All,
first let me say I'm an embedded programmer who as to do some work on a gui to connect a device. I've been asked to do it in QT. This is my first day working in QT so I'm unfamiliar with the correct wording so hope this explains. I've done some googling but am unable to find and answer, there seems to be a host of documents, but I really can't find an answer :s
So, I produced a basic gui in designer on linux/ubuntu. I've added a couple of labels and line edits, so I can fill line edit, eg name and version. All works OK.
I then added a cpp/h/class files called example, the class contains a sdt::string name and version. I've added a signal pointing to the line edits for name and version, that on pressing return do a slot. However the slots give me lots of options clear() repaint() ect. I can see they work, eg use clear() and hit return the name I've typed vanishes ect. However I want the signal to point to the class I produced and fill in the name version strings when return is pressed. So basically when I type in the box and hit return my own class string variable is populated with the name I've typed in.
Sorry I'm really brand new to QT and am unsure if my language / terms are correct, so its rather hard to explain.

Thanks for the help

Last edited by knobby67; 11-08-2013 at 11:53 AM.
 
Old 11-08-2013, 02:58 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,881
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You want to do something like this, correct?

Code:
-- somewhere else; where you define your custom class

slots:
    void do_this_because_the_button_was_clicked();
    // NOTE it must be under the slots: hierarchy to be usable as a connection point.

-- Your code

QPushButton *myButton = new QPushButton("HIT ME");

connect(this->myButton, SIGNAL(clicked()), this, SLOT(do_this_because_the_button_was_clicked()));
Qt and the associated forums offer many examples; however for someone not well initiated with their programming model, or other similar models, it's a bit daunting to start.

Signals and Slots

I started with this book but the version for Qt4, it helped but eventually one moves to checking for examples very rapidly. What I recommend is that you follow the initial examples and don't try to do the nice and pretty styling stuff you eventually want to have it look like; you first need to understand their programming model before you can start varying things outside their default boxes.

Recommended Reading
 
Old 11-09-2013, 04:39 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Thanks for the links, ill make them my weekend reading.
Like some other api stuff ive worked with in the past there's such a huge amount of info with much being out of it out of date it makes starting a daunting task.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: Size of a class containing a virtual function Aquarius_Girl Programming 17 10-23-2011 12:25 AM
[SOLVED] How can a friend function access a public function from a base class? lesca Programming 1 11-17-2010 01:56 PM
javascript - class / function in function jchambers Programming 3 06-15-2009 10:33 PM
how pass a class to a function aditya1 Programming 2 03-08-2005 09:02 PM
signal function. SIG_IGN? blackzone Programming 1 07-26-2004 05:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration