Thread: structure of a tcp driven qt interface

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    structure of a tcp driven qt interface

    hello

    i'm writing a little game: the engine is in nemerle, and the user interface is in qt in c++. the connection between the two is secured by a tcp connection.

    i have, say:
    - main.cpp
    - mainWindow class defined in mainwindow.h and implemented in mainwindow.cpp
    - canvasView class defined and implemented in canvasview.h

    i need to have:
    an instance of QSocket connected to the server

    my question is:
    where and how to define and implement the QSocket instance so that:
    - i can use its socketSend method both from mainwindow.cpp and canvasview.h;
    - its socketRead method can modify variables of the mainWindow instance defined in main.cpp, and the canvasView instance defined in mainWindow.cpp?

    i've tried lots of ways and none worked could you help me, please?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > - canvasView class defined and implemented in canvasview.h
    What's wrong with implemented in canvasview.cpp ?

    > an instance of QSocket connected to the server
    The existance of the object is declared in say main.cpp, and you pass references to it to whoever needs to know.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    thanks, it helped

    the thing is: i'm a newbie in c++ and must have been making some (probably, stupid) syntax mistakes, and thus never being able to compile the whole thing which finally led me to the conclusion that it is actually impossible.

    anyway, now it all works and my headache of the last couple of days is eventually over; man, you cured my head and soul thank you

    ps. well, canvasview is pretty small and i thought it would be more comfortable to have it all in one file. is there something wrong about doing so?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > is there something wrong about doing so?
    You'll find these problems later on
    1. the file gets compiled into every source file you include it in. If you have member functions outside the class, then these will become multiply declared at link time. If they're all inline, you just end up with code bloat.
    2. Any change to the implementation of canvasview will mean you have to recompile ALL the files which depend on it. The whole point of C++ is to separate the interface (.h) from the implementation (.cpp)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    oh, yes, i haven't thought about it... actually, i've kept doing "qmake -project && qmake && make", and the whole thing not being too huge it compiles reasonably fast so i thought it easier than defining which files i want compiled every time i make a little change somewhere.
    but of course, you are right

    thank you very much for help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. menu driven interface
    By weegi in forum C Programming
    Replies: 4
    Last Post: 04-17-2004, 04:08 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM