Results 1 to 6 of 6

Thread: Returning QPointer via function from one class to another, using the QPointer's data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Returning QPointer via function from one class to another, using the QPointer's data

    I've declared a qpointer to a QLineEdit pointer called txtNewCareer in the class Populate. I have created a getter function in Populate so other classes can access that pointer. It is a dynamically created pointer that creates a QLineEdit, which I need to keep as dynamic and on the heap.

    So, how do I appropriately call my getter function return_txtNewCareer()? I've had not problems returning regular pointers. But I am just learning how to use QPointers.
    As you can see I'm trying to connect a signal of the QPointer txtNewCareer by calling the return_txtNewCareer function of class Populate, to a slot in mainwindow class.

    Thanks.
    This is a skeleton of my classes with the basic information of what I'm doing.

    Populate.h
    Qt Code:
    1. #include <QPointer>
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. public:
    2. QLineEdit* return_txtNewCareer();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. private:
    2. QPionter<QLineEdit> txtNewCareer;
    To copy to clipboard, switch view to plain text mode 


    Populate.cpp
    Qt Code:
    1. QPointer<QLineEdit> txtNewCareer = new QLineEdit
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QLineEdit* Populate::return_txtNewCareer(){
    2. return txtNewCareer;
    3. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. connect(populate->return_txtNewCareer(), SIGNAL(textEdited(QString)), this, SLOT(txtNewCareer_edited(QString)));
    To copy to clipboard, switch view to plain text mode 

    I am unable to get the program to run. I have narrowed down the problem to the connect statement because I have commented it out and the program runs. When I run the program with the connect statement I get this Segmentation fault:

    Signal name : SIGSEGV
    Signal meaning : Segmentation fault
    Last edited by pditty8811; 19th March 2015 at 02:48.

Similar Threads

  1. Replies: 0
    Last Post: 27th September 2013, 06:09
  2. How to mix QScopedPointer with QPointer
    By jezz in forum Qt Programming
    Replies: 5
    Last Post: 14th April 2012, 08:20
  3. How to cast QPointer<T> to QPointer<childT>
    By cafu in forum Qt Programming
    Replies: 4
    Last Post: 19th March 2010, 10:51
  4. Problem using QPointer
    By weaver4 in forum Newbie
    Replies: 8
    Last Post: 20th February 2010, 05:05
  5. QMutableVectorIterator and QPointer?
    By Scorp2us in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2008, 19:39

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.