Page 1 of 3 123 LastLast
Results 1 to 20 of 50

Thread: Program crashes

  1. #1
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Program crashes

    Hi, when calling this:
    Qt Code:
    1. std::string final = tmp.substr(tmp.find(" "), tmp.length());
    2. m_chan = new Channel(this, QString(final.c_str()), socket);
    3. tabs->addTab(m_chan, QString(final.c_str()));
    To copy to clipboard, switch view to plain text mode 
    the program crahes without a reason. im sure the tmp has a " "
    PS:
    when i debug i get seg fault
    Last edited by Fallen_; 17th September 2010 at 06:30.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    Possible problems:

    tabs = 0
    m_chan = 0
    if socket is a pointer, it can be 0 too.

    So, do a check on all pointers, or check your backtrace to find which pointer is 0

  3. #3
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    already did, nothing wrong

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    Post your backtrace.

  5. #5
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    Did you mean this?:
    Signal name: SIGSEGV
    Signal meaning: Segmentation fault
    if not:
    http://pastebin.com/R5uubZPf
    ---The text that you have entered is too long (46227 characters). Please shorten it to 10000 characters long.
    anything else?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    No, that is the compiled code of a QWidget::setParent function.

    But it might get us closer to the error.
    If your program fails in this function, you're creating a widget with a non valid parent.

    I guess Channel is a widget?
    And the first argument in the constructor is the parent?
    Does "this" exist?

  7. #7
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    Channel is a widget yes, and "this" exist while calling it and yes the first arguemnt is QWidget

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    I would love to see the backtrace.

    What system are you using? Window, Linux, MacOs, ... ?
    What IDE are you using? Qt Creator, ... ?

  9. #9
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    Windows, Qt creator (to debug), and Qt Command Line to compile. how do i get the backtrace?

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    In Qt Creator, in stead of running the program normally, run the program in the debugger.
    When it crashes, go to the stack view (should be the list on the left I think), it should contain the backtrace.

  11. #11
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    nope, cant see anything

  12. #12
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Program crashes

    I'm not in front of my computer at the moment so I can't help you with that at the moment.

    But to give some more information:
    The backtrace is a list of functions that were the last functions being run in your program.
    The very last function in this list usually contains the crash. You can then follow the list of functions to see where the problem first occured.

    Segmentation faults happen when you try to access memory that you should never access (like the memory segment of the kernel). Most of the time this happens when the pointer to an object is 0.

    The stack list should be the list on the left in the debugging section of Qt Creator.

  13. #13
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes

    I agree that running in a debugger will be the fastest solution here. Another point: you never check the results of your "find" operation. Despite your insistence that there's a space to be found in the string, it's poor form not to check that the operation actually succeeded.

    You could also simply print the results of each line shown to cerr, which would at least isolate the line that is causing the problem. Printing out tmp prior to the string manipulations would also shed some light.

  14. #14
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    ok i have made something like this:
    Qt Code:
    1. if(sscanf(tmp.c_str(), "/join %s", buffer) > 0) {
    To copy to clipboard, switch view to plain text mode 
    and then read->append(buffer) and it worked but i commented out the:
    Qt Code:
    1. m_chan = new Channel(this, QString(buffer), socket);
    2. tabs->addTab(m_chan, QString(buffer));
    To copy to clipboard, switch view to plain text mode 
    so its something wrong with them.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crashes

    Is there any specific reason that you are using C strings and std::string instead of QString?

    Please show us the constructor of Channel.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    Qt Code:
    1. Channel::Channel(QWidget* parent, const QString& name, QTcpSocket* socket)
    2. : QWidget(parent), chan(name), m_socket(socket)
    3. {
    4. write = new QLineEdit;
    5. read = new QTextEdit;
    6. send = new QPushButton(tr("Send"));
    7. read->setReadOnly(true);
    8. QVBoxLayout* layout = new QVBoxLayout;
    9. layout->addWidget(read);
    10. layout->addWidget(write);
    11. layout->addWidget(send);
    12. setLayout(layout);
    13. setWindowTitle(name.toLatin1());
    14. connect(send, SIGNAL(clicked()), this, SLOT(sendM()));
    15. read->append("Welcome to " + name + "\n");
    16. }
    To copy to clipboard, switch view to plain text mode 

  17. #17
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Program crashes

    buffer is a QString. Print it out and see what it contains before using it.

    Or - still by far the best bet - run your code through a debugger and isolate the problem in a minute or two.

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crashes

    Could you print the value of buffer before calling the constructor?

    By the way, if you want to extract the argument to your "/join" command, you can do it this way:

    Qt Code:
    1. // assuming QString tmp holds the complete line (i.e. "/join #qt")
    2. // detect '/' followed by an alphanumeric string followed by a whitespace followed by some other text
    3. QRegExp commandRx("^/([A-Za-z][A-Za-z0-0]+)\\s(.*)$");
    4. if(commandRx.exactMatch(tmp)){
    5. // we have found a command
    6. QString cmdName = commandRx.cap(1); // command name (first set of brackets)
    7. QString arguments = commandRx.cap(2); // everything past the space (second set of brackets)
    8. cmdName = cmdName.toLower();
    9. if(cmdName == "join") {
    10. QStringList channels = arguments.split(" "); // split on spaces
    11. foreach(QString channel, channels) {
    12. if(channel.startsWith("#")) {
    13. joinChannel(channel.mid(1)); // join everything starting with '#'
    14. }
    15. }
    16. } else if(cmdName == ... ) {
    17. ...
    18. } ...
    19. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    man i already made it to get the text, now when i do something like this:
    Qt Code:
    1. tabs->addTab(new Channel(this, QString(buffer), socket, ""), QString(buffer));
    To copy to clipboard, switch view to plain text mode 
    it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything:
    Qt Code:
    1. Channel *chan = new Channel(this, channel.c_str(), socket, tmp);
    2. chan->printText(tmp);
    To copy to clipboard, switch view to plain text mode 
    any ideas?

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Program crashes

    Quote Originally Posted by Fallen_ View Post
    man i already made it to get the text,
    I'm aware of it, the point is you are doing it with a C api that is cumbersome and error prone.

    it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything
    I have no idea what you mean. What is printText(), what other function and what was it supposed to do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. qstringlist array crashes program
    By chrisb123 in forum Newbie
    Replies: 4
    Last Post: 23rd October 2009, 16:03
  2. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 12:52
  3. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 10:27
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 21:09
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 20:32

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.