Results 1 to 20 of 27

Thread: Reading from TCP Socket crashes program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by OnionRingOfDoom
    and then the client crashes.
    And there was only one entry in the backtrace? Did you compile your application in debug mode?

    Anyway, you try to read data from the socket before they arrive --- you must wait for readyRead() signal.

  2. #2

    Default Re: Reading from TCP Socket crashes program

    ...How do I compile it in debug mode?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by OnionRingOfDoom
    ...How do I compile it in debug mode?
    Add "CONFIG += debug" to your .pro file (and remove "release" if it's there).

  4. #4

    Default Re: Reading from TCP Socket crashes program

    Ok so I changed the connection to do the readSpeed() function whenever readyRead() was emitted. However, now nothing happens when the client connects.

    I also added a new connection at the end of the acceptConnection() function, which is as follows: connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sendSpeed()));
    so now, whenever I move the slider (and it outputs valueChanged signal), it crashes.
    Last edited by OnionRingOfDoom; 26th January 2006 at 22:08.

  5. #5

    Default Re: Reading from TCP Socket crashes program

    After further fiddling, it seems that it's not the server's writing to the IO device that's the problem, it's the client's reading from the IO device that's causing the crash. Moving the slider thus causes the server to write data, and the client tries to read it or something, but crashes.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Does it crash if you change MainWindow::readSpeed() to:
    Qt Code:
    1. void MainWindow::readSpeed()
    2. {
    3. label->setNum(0);
    4. }
    To copy to clipboard, switch view to plain text mode 
    ?

    Did you try to generate that backtrace again?

  7. #7

    Default Re: Reading from TCP Socket crashes program

    yes, it still crashes, oddly enough...
    and I'm trying to compile in debug mode, but I have to fix all these errors switching to debug mode seems to have created.

  8. #8

    Default Re: Reading from TCP Socket crashes program

    Oh awesome! It's acting like it can't find the QtNetwork include file anymore...
    Any idea why adding that CONFIG thing to the .pro file would make it think it couldn't find QtNetwork, but could still find every other Qt file I included?
    Last edited by OnionRingOfDoom; 26th January 2006 at 23:07.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by OnionRingOfDoom
    yes, it still crashes, oddly enough...
    Is that label variable initialized?

    Quote Originally Posted by OnionRingOfDoom
    It's acting like it can't find the QtNetwork include file anymore...
    Can it find "QTcpSocket? Did you compile Qt in debug mode or maybe you have only release version?

  10. #10

    Default Re: Reading from TCP Socket crashes program

    First question: yes, it is initialised
    And I fixed the other problem, when I remade the .pro file, it didn't put in the
    QT += network thing.
    Last edited by OnionRingOfDoom; 27th January 2006 at 00:12.

  11. #11

    Default Re: Reading from TCP Socket crashes program

    and now it almost finishes compiling in debug mode... but MinGW comes up with some weird error I'm totally not responsible for:

    C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\ mingw32\bin\ld.exe: cannot find -lqtmain

    But at least it still compiles in release mode. But it still crashes whenever the client trys to even do anything with the readyRead function.
    Last edited by OnionRingOfDoom; 27th January 2006 at 00:29.

  12. #12

    Default Re: Reading from TCP Socket crashes program

    Anyone else got any ideas?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by OnionRingOfDoom
    but MinGW comes up with some weird error I'm totally not responsible for
    Did you compile Qt in debug mode? Do you have the libqtmain.a and libqtmaind.a files in %QTDIR%\lib directory?

    But it still crashes whenever the client trys to even do anything with the readyRead function.
    Does it crash with empty MainWindow::readSpeed()?

    Also add "CONFIG += console" to your .pro file and see whether your program outputs something to the console.

  14. #14

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by jacek
    Does it crash with empty MainWindow::readSpeed()?

    Also add "CONFIG += console" to your .pro file and see whether your program outputs something to the console.
    No, it does not crash when readSpeed() is empty.
    And no, it doesn't write anything to the console.

    I'm gonna try to reinstall Qt in debug mode this afternoon, after school

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading from TCP Socket crashes program

    Quote Originally Posted by OnionRingOfDoom
    No, it does not crash when readSpeed() is empty.
    Could you post the line in which you initialize that label variable?

  16. #16

    Default Re: Reading from TCP Socket crashes program

    As for the label, it's initialized like so:

    Qt Code:
    1. QLabel *label = new QLabel("change");
    To copy to clipboard, switch view to plain text mode 

    ...............

    Wait a sec...... *checks the .h file*

    Oh....
    I initialised the label variable twice....
    **facepalms**
    problem solved....
    Last edited by OnionRingOfDoom; 27th January 2006 at 19:29.

  17. #17

    Default Re: Reading from TCP Socket crashes program

    Heh, thanks for your help through all this! I tend to have other people ask me some question and then I realise a stupid error I made...

Similar Threads

  1. wrong connection? program crashes altough it compiles
    By cbarmpar in forum Qt Programming
    Replies: 7
    Last Post: 30th September 2008, 12:48
  2. Socket Reading Advice
    By tntcoda in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2008, 11:26
  3. Program crashes with assert error in xcb_lock.c
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2007, 19:56
  4. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  5. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04: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
  •  
Qt is a trademark of The Qt Company.