Results 1 to 3 of 3

Thread: Unable to access members of same class, giving seg fault

  1. #1
    Join Date
    Mar 2013
    Location
    Hyderabad,Bangalore,India
    Posts
    70
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Unable to access members of same class, giving seg fault

    I am trying to create a slot from object to other
    frame to log , but both belongs to same class

    when trying to access objects placed on log , they are becoming invalid.

    how to solve the problem?

    Qt Code:
    1. QWidget* ApplicationLog::createLogWindow()
    2. {
    3. m_pCmdLogHL = new QHBoxLayout(this);
    4. m_pLogTE = new QTextEdit(this);
    5. m_pCmdLogHL->addWidget(m_pLogTE);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QWidget* ApplicationLog::createFrameWindow()
    2. {
    3. m_pButtonsHL = new QHBoxLayout(this);
    4. m_pMinMaxBut = new Button(this,"Minimize");
    5. connect(m_pMinMaxBut,SIGNAL(clicked()),this,SLOT(logWindowMinMax()));
    6. m_bIsMaximize = 1;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ApplicationLog::logWindowMinMax()
    2. {
    3. qDebug()<<"slot invoked" ;
    4. if(m_bIsMaximize)
    5. {
    6. m_pLogTE->setVisible(false);
    7. m_pMinMaxBut->setTooltip("Maximize");
    8. m_bIsMaximize = 0;
    9. }
    10. else
    11. {
    12. m_pLogTE->setVisible(true);
    13. m_bIsMaximize = 1;
    14. m_pMinMaxBut->setTooltip("Minimize");
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    in the main window i am calling
    Qt Code:
    1. QWidget* frame = framewindow->createFrameWindow();
    2. QWidget* log = logwindow->createLogWindow();
    To copy to clipboard, switch view to plain text mode 
    this particular line is giving problem (segmentation)
    Qt Code:
    1. m_pLogTE->setVisible(false);
    To copy to clipboard, switch view to plain text mode 

    why is it wrong to access that object,how to access the object?

  2. #2
    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: Unable to access members of same class, giving seg fault

    No return statements in functions returning non-void:
    Qt Code:
    1. QWidget* ApplicationLog::createLogWindow()
    2. {
    3. m_pCmdLogHL = new QHBoxLayout(this);
    4. m_pLogTE = new QTextEdit(this);
    5. m_pCmdLogHL->addWidget(m_pLogTE);
    6. // return !
    7. }
    8.  
    9. QWidget* ApplicationLog::createFrameWindow()
    10. {
    11. m_pButtonsHL = new QHBoxLayout(this);
    12. m_pMinMaxBut = new Button(this,"Minimize");
    13. connect(m_pMinMaxBut,SIGNAL(clicked()),this,SLOT(logWindowMinMax()));
    14. m_bIsMaximize = 1;
    15. // return !
    16. }
    To copy to clipboard, switch view to plain text mode 

    Another thing, check if createLogWindow() is called before trying to access m_pLogTE object.
    Last edited by stampede; 25th October 2013 at 13:29. Reason: updated contents

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Unable to access members of same class, giving seg fault

    The OP's code won't even compile, much less execute, so obviously we are not seeing the whole story. As amleto says in every post:

    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 2
    Last Post: 29th December 2011, 12:27
  2. Replies: 4
    Last Post: 17th January 2011, 14:05
  3. Replies: 1
    Last Post: 9th January 2011, 07:20
  4. Abstract base class and inherited class members
    By JovianGhost in forum General Programming
    Replies: 3
    Last Post: 19th March 2010, 12:32
  5. Replies: 4
    Last Post: 26th June 2007, 19:19

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.