Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: segmentation fault

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default segmentation fault

    Hello, i get a segmentation fault when i emit a signal, down here there are some snippet of code, maybe somebody can give me a hint.
    Thanks

    clientsocket.h
    Qt Code:
    1. #include <QTcpSocket>
    2. #include <QtGui>
    3. #include "callApplication.h"
    4.  
    5. class ClientSocket : public QTcpSocket
    6. {
    7. Q_OBJECT
    8.  
    9. private slots:
    10. void generateError();
    11. void readClient();
    12.  
    13. private:
    14. CallApplication *callApplication;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    clientsocket.cpp
    Qt Code:
    1. ClientSocket::ClientSocket(QTextBrowser *textBrowser)
    2. {
    3. connect(this->callApplication, SIGNAL(error()), this, SLOT(generateError())); //<-- segmentation fault
    4. connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
    5. }
    6.  
    7. ClientSocket::readClient(){
    8. //read something from client...
    9. callApplication = new CallApplication(this->textBrowserPark);
    10. }
    To copy to clipboard, switch view to plain text mode 

    callApplication.h
    Qt Code:
    1. #include <QProcess>
    2.  
    3. class CallApplication : public QObject
    4. {
    5. Q_OBJECT
    6. signals:
    7. void error();
    8. private:
    9. performApplication();
    10. public:
    11. QProcess process;
    12. };
    To copy to clipboard, switch view to plain text mode 

    callApplication.cpp
    Qt Code:
    1. void CallApplication::performApplication()
    2. {
    3. emit error();
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: segmentation fault

    Nothing has been assigned to "this->callApplication" by the time of connect(). In other words, it's an uninitialized pointer pointing to random memory garbage.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    this->callApplication is uninitialized - pointer points to somewhere.

    You shall always initialize pointers:
    Qt Code:
    1. ClientSocket::ClientSocket(QTextBrowser *textBrowser)
    2. :callApplication(NULL)
    3. {
    4. ...
    To copy to clipboard, switch view to plain text mode 

    Second:
    You need to pass a valid object to connect.

  4. #4
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    Quote Originally Posted by jpn View Post
    Nothing has been assigned to "this->callApplication" by the time of connect(). In other words, it's an uninitialized pointer pointing to random memory garbage.
    Again too slow!

  5. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    i got it, but if i try to do in this way
    clientSocket.cpp
    Qt Code:
    1. ClientSocket::ClientSocket(QTextBrowser *textBrowser):callApplication(NULL)
    2. {
    3. //callApplication = new CallApplication(this->textBrowserPark);
    4. connect(this->callApplication, SIGNAL(error()), this, SLOT(generateError()));
    5. }
    To copy to clipboard, switch view to plain text mode 

    in this way i don't have the segmentation fault but this error:
    QObject::connect: Cannot connect (null)::error() to ClientSocket::generateError()
    anyway when i emit the error signal the callApplication class is already initialized cos i have called the readClient() method...

  6. #6
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    move the connect statement to your readClient()-method then.

  7. The following user says thank you to DeepDiver for this useful post:

    mattia (6th November 2007)

  8. #7
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    Done. Now it's ok. Thanks so much!

  9. #8
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    Hello, i'm here again with another problem like last one, when the "error" signal is emitted into a slot called by a signal generated from QProcess i can't hook it. Down here the code.
    Thanks

    clientsocket.h
    Qt Code:
    1. #include <QTcpSocket>
    2. #include <QtGui>
    3. #include "callApplication.h"
    4.  
    5. class ClientSocket : public QTcpSocket
    6. {
    7. Q_OBJECT
    8.  
    9. private slots:
    10. void error();
    11. void readClient();
    12.  
    13. private:
    14. CallApplication *callApplication;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    clientsocket.cpp
    Qt Code:
    1. ClientSocket::ClientSocket(QTextBrowser *textBrowser)
    2. {
    3. callApplication = new CallApplication(this->textBrowserPark);
    4. connect(callApplication, SIGNAL(error(const QString)), this, SLOT(generateError(const QString)));
    5. connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
    6. }
    7.  
    8. ClientSocket::readClient(){
    9. //read something from client...
    10. callApplication->performApplication();
    11. }
    12.  
    13. void ClientSocket::error(QString error)
    14. {
    15. //send a string to the client
    16. }
    To copy to clipboard, switch view to plain text mode 

    callApplication.h
    Qt Code:
    1. #include <QProcess>
    2.  
    3. class CallApplication : public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. CallApplication();
    8. signals:
    9. void error();
    10. private:
    11. performApplication();
    12. private slots:
    13. void updateError();
    14. void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
    15. void processError(QProcess::ProcessError error);
    16. public:
    17. QProcess process;
    18. };
    To copy to clipboard, switch view to plain text mode 

    callApplication.cpp
    Qt Code:
    1. CallApplication::CallApplication()
    2. {
    3. connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(updateError()));
    4. connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
    5. connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
    6. }
    7.  
    8. void CallApplication::performApplication()
    9. {
    10. emit error(); //this is working correctly, signal connected into clientsocket.cpp
    11. }
    12.  
    13. void CallApplication::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    14. {
    15. if (exitStatus == QProcess::CrashExit) {
    16. } else if (exitCode != 0) {
    17. emit error("Qprocess ended"); //it dosen't work, neither the signals emit into processError, signal connected into clientsocket.cpp
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    You have defined a signal error().
    The definition of error(const QString&) is missing.

  11. #10
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    yes you are rigth i've forgotten a slice of code, now, into callApplication.h on line 9 i'added void error(QString error); but in my code it was already present, without it i can't hook the signal nowhere.

  12. #11
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    Make sure the signature of the signal declaration and the signature of the signal in the connect call are identical.

    signal:
    void error(QString)

    and
    connect(...., SIGNAL(error(const QString)), ...)

    are not the same.

  13. #12
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    ok, i deleted the const attribute...
    connect(...., SIGNAL(error(QString)), ...)
    but i can't call the slot "error" in the QProcess method:
    updateError()
    processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    processError(QProcess::ProcessError error)

    while in the performApplication() i can do it...and they are in the same class.
    thx

  14. #13
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    Which platform do you use?
    Run your application from the command line/console and watch out for warnings/errors there.

    Note: on Windows you need to add : CONFIG += console to your project file.
    as described here: http://doc.trolltech.com/4.3/qfile.html#open-4

  15. #14
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    i'm using linux and when i run it into the shell i get no warnings/errors

    edit:
    for example i tried to define another method in classApplication.h and i implemented it into classApplication.cpp, this method print something into the consolle, if i call it into performApplication() it works, if i call it into
    updateError()
    processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    processError(QProcess::ProcessError error)
    it doesn't work so i can deduce that it isn't just a signal/slot problem
    Last edited by mattia; 6th November 2007 at 11:39.

  16. #15
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    Hmmm - hard to tell.
    Post the whole project zipped - I will have a look.

  17. #16
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    you can find whole code here
    thanks so much!

  18. #17
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    As far as I can see the slots connected to process are never called.
    Looks like you never do anything with process.

    In this case it's quite logic that you never get the signal emitted.

  19. #18
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault

    When i call the process, for example RDP i can see the virtual terminal opening on my screen so i think the slot connected to the process are called, I've tried to print a string into the QTextBrowser to see if i'm really jump into that slot and i'm able to print it ...

    EDIT: maybe the signal is not emitted by callApplication but by QProcess, given that i'm trying to hook a signal (error) that it is emitted by another slot called by QProcess, in this case mi connect definition is not valide. Is it possible?
    Last edited by mattia; 6th November 2007 at 12:39.

  20. #19
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault

    Yeah - you are right. rdesktop was not installed on my machine ......

    I did enable emitting the signal in callApplication:: processFinished and did add qDebug() statements in callApplication:: processFinished and ClientSocket::generateError().

    As far as I can see the signal is emitted correctly.

    The message is not sent from server to the client or not displayed in the client gui.

  21. #20
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segmentation fault


    but in ClientSocket::generateError(QString error) i added
    this->textBrowserPark->setHtml("generate error..." + error);
    to show in the server QTextBrowser if i'm calling generateError method, and it don't show nothing...this should be put in evidence the fact thet i'm not calling the slot...

Similar Threads

  1. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 11:49
  2. Process aborted. Segmentation fault
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 09:12
  3. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 17:35
  4. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 17:52
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 17:30

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.