Results 1 to 6 of 6

Thread: Same socket in multiple classes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Unhappy Same socket in multiple classes

    This might be a general programming question, but since I'm using Qt i thought this would be the right place to ask. I'm programming a GUI client-server application. I'm encountering some difficulties on the client side. I have a login class in which I'm using a socket for the connection ( the user is prompted to introduce IP address and PORT in order to move on). Next, I have some sort of a menu. I want to use the same socket, but since it's declared in the login class, I can't (at this moment). I already tried to use inheritance; it looks something like:

    class Footbal : public QDialog, public Login

    But I get an error:

    ‘QObject’ is an ambiguos base of ‘Footbal’ - 4 times. And a warning : Class Footbal inherits from two QObject subclasses QDialog and Login. This is not supported!

    From what I noticed, it's because of QDialog - I tried to use QApplication instead but I got errors since I work with setModal() function.
    I really need an alternative. Singleton pattern would be the worst case scenario since I'm terrible at design patterns.

    Thanks for reading all this much

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Same socket in multiple classes

    If you need access to the socket then just pass the socket to whatever code needs it.

    Either using a getter in Login to return the socket pointer or let Login emit the socket through a signal when login succeeded.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Same socket in multiple classes

    If i try to create an int type getter i get:
    error: invalid conversion from 'QTcpSocket*' to 'int' [-fpermissive]
    If i try to create an QTcpSocket getter i get an error related to QTcpSocket class file. I'm still unable to make it work

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Same socket in multiple classes

    Well, int is obviously not the same as a pointer to QTcpSocket, no?

    Qt Code:
    1. QTcpSocket Login::socket() const
    2. {
    3. return m_socket;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Same socket in multiple classes

    I get an error message:
    C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtNetwork\q tcpsocket.h:64: error: 'QTcpSocket::QTcpSocket(const QTcpSocket&)' is private
    Q_DISABLE_COPY(QTcpSocket)
    ^

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Same socket in multiple classes

    Yes, typo, sorry. As I said return a pointer. Missed the *

    Qt Code:
    1. QTcpSocket *Login::socket() const
    2. {
    3. return m_socket;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Multiple setAxisScaleDraw classes
    By KenJustKen in forum Qwt
    Replies: 2
    Last Post: 13th November 2011, 19:25
  2. Replies: 2
    Last Post: 22nd May 2011, 21:31
  3. Emit one signal from multiple classes
    By Ishmael in forum Qt Programming
    Replies: 4
    Last Post: 28th June 2010, 23:57
  4. How do you run multiple test classes?
    By jeffadams78 in forum Qt Programming
    Replies: 3
    Last Post: 2nd April 2009, 18:39

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.