Results 1 to 20 of 50

Thread: Program crashes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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?

  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

    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.

  3. #3
    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

  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

    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.

  5. #5
    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.

  6. #6
    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  8. #8
    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 

  9. #9
    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  11. #11
    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?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


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

    Default Re: Program crashes

    its to append a text in the "read" text edit

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

    Default Re: Program crashes

    Quote Originally Posted by wysota View Post
    I'm aware of it, the point is you are doing it with a C api that is cumbersome and error prone.


    I have no idea what you mean. What is printText(), what other function and what was it supposed to do?
    Well, the printText is a function in the "Channel" class when calling it from the "MainWindow" class it doesnt print text in the "read" textEdit, heres what printText supposed to do:
    Qt Code:
    1. void Channel::printText(const QString& text)
    2. {
    3. read->append(text);
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. qstringlist array crashes program
    By chrisb123 in forum Newbie
    Replies: 4
    Last Post: 23rd October 2009, 15:03
  2. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 11:52
  3. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 09:27
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 19: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
  •  
Qt is a trademark of The Qt Company.