Results 1 to 3 of 3

Thread: Is it possible to use other things than widgets in Designer?

  1. #1
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is it possible to use other things than widgets in Designer?

    Hello,

    I'm busy with making a chat program with Qt. I already made some plugins for Designer (a widget ith buttons for the connection and an exit button, and a widget that forms the chatwindow, see my other thread in the designer forum for that).

    I'd like it if it were possible to create a widget or QObject that handles the network part (I already created some network functions with the RakNet library before I used Qt), because I like the simplicity of connecting signals and slots in Designer.

    Is it possible to make a plugin of a QObject, instead of a QWidget and place that in a form in Designer?

    Any suggestions on my code are welcome, too.

    network.h:
    Qt Code:
    1. #ifndef NETWORK_H
    2. #define NETWORK_H
    3.  
    4. #include "RakNet/BitStream.h"
    5. #include "RakNet/RakClientInterface.h"
    6. #include "RakNet/RakNetworkFactory.h"
    7. #include "RakNet/RakServerInterface.h"
    8. #include "RakNet/PacketEnumerations.h"
    9.  
    10. #ifdef _WIN32
    11. #include "Windows.h" //sleep
    12. #endif
    13.  
    14. class Network : public QObject
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. Network(QObject *parent=0);
    20. ~Network(void);
    21.  
    22.  
    23. public slots:
    24. void connect(void);
    25. void disconnect(void);
    26.  
    27. void sendInt(char *outmessage);
    28. void sendData(char *outmessage);
    29.  
    30. signals:
    31. void connecting(bool success);
    32. void connectionAccepted(void);
    33. void disconnection(void);
    34. void chatMessage(const QString &message);
    35.  
    36.  
    37. private:
    38. RakClientInterface* clientInterface;
    39. Packet* p;
    40.  
    41. void receive(void);
    42. void handleBitStream(Packet* a);
    43. void handleIntStream(Packet* a);
    44. };
    45.  
    46. #endif
    To copy to clipboard, switch view to plain text mode 

    network.cpp:
    Qt Code:
    1. #include <QObject>
    2. #include "network.h"
    3.  
    4. Network::Network(QObject *parent)
    5. : QObject(parent)
    6. {
    7. clientInterface = RakNetworkFactory::GetRakClientInterface();
    8. }
    9.  
    10. Network::~Network()
    11. {
    12. //shut down
    13. if(clientInterface)
    14. RakNetworkFactory::DestroyRakClientInterface(clientInterface);
    15. }
    16.  
    17. void Network::connect()
    18. {
    19. char ip[14]="127.0.0.1";
    20.  
    21. char port[6]="44394";
    22.  
    23. if(clientInterface->Connect(ip, atoi(port), 0, 0, 30))
    24. {
    25. emit connecting(true);
    26. }
    27. else
    28. {
    29. emit connecting(false);
    30. }
    31. }
    32.  
    33. void Network::disconnect()
    34. {
    35. clientInterface->Disconnect(30);
    36. }
    37.  
    38. void Network::sendInt(char* outmessage)
    39. {
    40. RakNet::BitStream outstream;
    41. outstream.Write(ID_INT);
    42. outstream.Write(atoi(outmessage));
    43. if(clientInterface)
    44. clientInterface->Send(&outstream, HIGH_PRIORITY, RELIABLE_ORDERED, 0 );
    45. outstream.Reset();
    46. }
    47.  
    48. void Network::sendData(char* outmessage)
    49. {
    50. RakNet::BitStream outstream;
    51. outstream.Write(ID_TEST);
    52. outstream.Write((int)strlen(outmessage));
    53. outstream.Write(outmessage, (int)strlen(outmessage));
    54. if(clientInterface)
    55. clientInterface->Send(&outstream, HIGH_PRIORITY, RELIABLE_ORDERED, 0 );
    56. outstream.Reset();
    57. }
    58.  
    59. void Network::receive()
    60. {
    61. if(clientInterface)
    62. {
    63. p = clientInterface->Receive();
    64. }
    65.  
    66. if(p)
    67. {
    68. switch(p->data[0])
    69. {
    70. case ID_CONNECTION_REQUEST_ACCEPTED:
    71. emit verbindingGeaccepteerd();
    72. break;
    73. case ID_RECEIVED_STATIC_DATA:
    74. printf("Static data received.\n");
    75. break;
    76. case ID_DISCONNECTION_NOTIFICATION:
    77. emit disconnect();
    78. break;
    79. case ID_TEST:
    80. //printf("Test message coming in.\n");
    81. handleBitStream(p);
    82. break;
    83. case ID_INT:
    84. //printf("Int message coming in.\n");
    85. handleIntStream(p);
    86. break;
    87. default:
    88. printf("Packet incoming with identifier %i.\n", p->data[0]);
    89. break;
    90. }
    91. if(clientInterface)
    92. clientInterface->DeallocatePacket(p);
    93. }
    94. }
    95.  
    96. void Network::handleBitStream(Packet* a)
    97. {
    98. RakNet::BitStream bitStream((char*)a->data, a->length, false);
    99. char* incmessage;
    100. unsigned int messagelength=0;
    101. bitStream.IgnoreBits(32); //sizeof(unsigned char)*8); // Ignore the packet type enum
    102. bitStream.Read(messagelength);
    103. //printf("%i\n",messagelength);
    104. incmessage=new char[messagelength];
    105. if(bitStream.Read(incmessage, messagelength))
    106. {
    107. emit chatMessage(QString(incmessage)); //incmessage); //printf("\tDe ander zegt: %s\n",incmessage);
    108. }
    109. else
    110. {
    111. //printf("Message error.\n");
    112. }
    113. bitStream.Reset();
    114. }
    115.  
    116. void Network::handleIntStream(Packet* a)
    117. {
    118. RakNet::BitStream bitStream((char*)a->data, a->length, false);
    119. int intje=0;
    120. bitStream.IgnoreBits(sizeof(ID_INT)*8); // Ignore the packet type enum
    121. if(bitStream.Read(intje))
    122. {
    123. emit chatBericht(QString(QChar(intje)));
    124. }
    125. else
    126. {
    127. //printf("Message error.\n");
    128. }
    129. bitStream.Reset();
    130. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by hansmbakker; 14th February 2006 at 14:10.

  2. #2
    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: Is it possible to use other things than widgets in Designer?

    No, Designer can only use widgets. But you can use auto-connecting features of Qt4 -- if you name a slot on_xxx_yyy(), it will be auto-connected to yyy signal of xxx object.

  3. #3
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to use other things than widgets in Designer?

    Thank you. Comments on my code are always welcome btw

Similar Threads

  1. Replies: 8
    Last Post: 16th January 2009, 17:10
  2. Cannot drop widgets in Qt Designer 4.4.0
    By DerSchoeneBahnhof in forum Qt Tools
    Replies: 2
    Last Post: 19th June 2008, 18:18
  3. Global includes with designer custom widgets
    By mab in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2006, 23:06
  4. Designer crashes when selecting some widgets
    By gwendal in forum Qt Tools
    Replies: 4
    Last Post: 21st July 2006, 14:18
  5. How to create pop up widgets in designer.
    By gsQT4 in forum Qt Tools
    Replies: 1
    Last Post: 25th May 2006, 17:40

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.