Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 50

Thread: Program crashes

  1. #21
    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

  2. #22
    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

    If you have still problems with the crash, put your code into a zip file and attach it to your post and I'll see what the problem is.

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

  4. #24
    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

    And how do you call it from MainWindow?
    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.


  5. #25
    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* chan = new Channel(this, channel.c_str(), socket);
    2. chan->printText(tmp);
    To copy to clipboard, switch view to plain text mode 

  6. #26
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Program crashes

    I guess that's because you create that C-style string pointer, if you want to create a QString from a std::string don't use the .c_str() method, use the static member function of QString fromStdString() (this create a copy of the string)

    It has been said: it's better if you use QString instead std::string (and C-style strings)

  7. #27
    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
    Qt Code:
    1. Channel* chan = new Channel(this, channel.c_str(), socket);
    2. chan->printText(tmp);
    To copy to clipboard, switch view to plain text mode 
    And the program runs but the text is not printed? What is the content of "tmp" at this moment?
    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. #28
    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
    And the program runs but the text is not printed? What is the content of "tmp" at this moment?
    tmp is a char array with the received messages from the socket and ye it doesnt print the text.
    Quote Originally Posted by Zlatomir View Post
    I guess that's because you create that C-style string pointer, if you want to create a QString from a std::string don't use the .c_str() method, use the static member function of QString fromStdString() (this create a copy of the string)

    It has been said: it's better if you use QString instead std::string (and C-style strings)
    nope still doesnt work
    Last edited by Fallen_; 18th September 2010 at 21:56.

  9. #29
    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
    tmp is a char array with the received messages from the socket and ye it doesnt print the text.
    I'm asking what it contains - literally. Please print it to your console, don't assume you know what's in there.
    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.


  10. #30
    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 asking what it contains - literally. Please print it to your console, don't assume you know what's in there.
    thats what written in there:
    Qt Code:
    1. :stockholm.se.quakenet.org 366 Fallen_ #Fallen :End of /NAMES list.
    2.  
    3. [00:45:51] Fallen_ has joined #Fallen
    To copy to clipboard, switch view to plain text mode 

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

    And how did you print that to the console?
    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.


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

    Default Re: Program crashes

    using qDebug()?

  13. #33
    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

    Show us the statement please. With a couple of surrounding lines.
    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.


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

    Default Re: Program crashes

    ive showed u 2 lines already, the problem is not the lines....
    Last edited by wysota; 19th September 2010 at 22:21. Reason: Removed improper words

  15. #35
    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
    the **** u mean? ive showed u 2 lines already, the problem is not the lines....
    The code, not the text.
    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. #36
    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

    Quote Originally Posted by Fallen_ View Post
    ive showed u 2 lines already, the problem is not the lines....
    Look - programs are a compendium of statements that operate on data. If you're having a problem, it can only be in one of two places - the statements, or the data those statements operate on.

    You've been asked to print out the strings your program makes use of - not just the input strings, but the strings after you've gotten done munging around with them. The strings that you feed to your program statements. If the input data is wrong (and frankly, this seems likely, given that you're attempting to transform between three different string manipulation libraries) then your statements aren't going to produce the results you expect.

    So far, in two full pages, you've produced the single, top-level input string, but none of what was actually asked for.

    Also, although many people frown upon it, "printf-style" debugging is often a fast, efficient means to find out what's wrong with your program. Yes, a debugger will usually get you there faster. But especially when working with potentially corrupt strings, simply dumping those strings to a console often provides you (or those you're asking to do your work for you) valuable clues about what the problem may actually be.

    You've also refused to produce code, despite a number of such requests.

    If you can't play along, figure it out for yourself; you've been given far more than enough guidance to do so. If, however, you want others to help you, you're going to have to respond fully and accurately - and politely - when those you're asking for help request additional information.

  17. #37
    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
    The code, not the text.
    Qt Code:
    1. void MainWindow::appendToWindow()
    2. {
    3. char buffer[1024], tmp[1024];
    4. while(socket->canReadLine()) {
    5. socket->readLine(buffer, sizeof(buffer));
    6. std::string str = buffer;
    7. std::string name = getName(buffer), msg = getMsg(buffer), channel = getChannel(buffer), t = getTime();
    8. if(connected) {
    9. if(str.substr(0, 4) == "PING") {
    10. std::string s = "PO" + str.substr(2) + "\r\n";
    11. socket->write(s.c_str());
    12. }
    13. else if(str.find("PRIVMSG") != std::string::npos)
    14. sprintf(tmp, "%s <%s>(%s) %s", t.c_str(), name.c_str(), channel.c_str(), msg.c_str());
    15. else if(str.find("NOTICE") != std::string::npos)
    16. sprintf(tmp, "%s Notice from: %s Message: %s", t.c_str(), name.c_str(), msg.c_str());
    17. else if(str.find("JOIN") != std::string::npos)
    18. sprintf(tmp, "%s %s has joined %s", t.c_str(), name.c_str(), channel.c_str());
    19. else if(str.find("PART") != std::string::npos)
    20. sprintf(tmp, "%s %s has left %s (%s)", t.c_str(), name.c_str(), channel.c_str(), msg.c_str());
    21. else if(str.find("QUIT") != std::string::npos)
    22. sprintf(tmp, "%s %s has quit (%s)", t.c_str(), name.c_str(), msg.c_str());
    23. else
    24. read->append(buffer);
    25.  
    26. Channel* chan = new Channel(NULL, QString::fromLatin1(channel.c_str()), NULL);
    27. chan->printText(QString::fromLatin1(tmp));
    28. read->append(tmp);
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  18. #38
    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

    The code you pasted does not contain the qDebug statement I asked you for...
    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. #39
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes

    it had it, but i removed it since its not needed but the lines are 26-28 (read->append(tmp) is the read text edit from the MainWindow so i know that theres still text))

  20. #40
    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

    In that case I have no idea what you want. From what I understood from post #23 you said read->append(tmp) didn't work. So what's the problem exactly? Try to be as specific and clear as you can.
    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, 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.