Results 1 to 13 of 13

Thread: cannot write to QListWidget or QLineEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Aug 2008
    Posts
    38
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    19

    Default

    Thanks I'll try that !

    Strange that QApplication:rocessEvents(); didn't help!

    getting a message from qtcentre but it states that popup blocker is the problem.

    I think I have the code as you recommended. Still doesn't work!

    The tcp/ip section still works under the cover of the gui.

    BTW the gui features (close, etc) are also locked up!

    Can't be far from success!

    The Qt documentation example for QThread uses run().

    Qt Code:
    1. // tcpip.h
    2. #ifndef TCPIP_H
    3. #define TCPIP_H
    4. #include <QThread>
    5. #include <QtGui/QWidget>
    6. #include "ui_tcpip.h"
    7. class tcpip_client;
    8. class tcpip : public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. tcpip(QWidget *parent = 0);
    14. ~tcpip();
    15.  
    16. private:
    17. Ui::tcpipClass ui;
    18. ushort port;
    19. private slots:
    20. void StartTCPServer();
    21. void StartTCPClient();
    22. void str_client(tcpip_client* tcpip_x, Ui::tcpipClass ui);
    23. void currChanged(QWidget*);
    24. };
    25. class tcpipThread : public QThread
    26. {
    27. Ui::tcpipClass ui;
    28. ushort port;
    29. public:
    30. tcpipThread( Ui::tcpipClass uiparm, unsigned portParam):ui(uiparm),port(portParam)
    31. {}
    32. void run(){}
    33. void start();
    34. };
    35.  
    36. #endif // TCPIP_H
    37.  
    38. // tcpip.cpp
    39.  
    40. #include "tcpip.h"
    41. #include "tcpip_server.cpp"
    42. #include "tcpip_client.cpp"
    43. #include <iostream>
    44. //#include <QtDebug>
    45. tcpip::tcpip(QWidget *parent)
    46. : QWidget(parent)
    47. {
    48. ui.setupUi(this);
    49. connect( ui.pushButtonStartTCPServer, SIGNAL(clicked()), this, SLOT(StartTCPServer()) );
    50. connect( ui.pushButtonStartTCPClient, SIGNAL(clicked()), this, SLOT(StartTCPClient()) );
    51.  
    52. ui.listWidgetServer->addItem(QString("server constructor"));
    53.  
    54. }
    55.  
    56. tcpip::~tcpip()
    57. {
    58. }
    59. void tcpip::StartTCPServer()
    60. {
    61. ui.listWidgetServer->addItem(QString("server StartTCPServer"));
    62.  
    63. // QApplication::processEvents();
    64. bool ok = true;
    65. QString qstr = ui.lineEditTCPIPServerPortServer->text();
    66. port = qstr.toInt(&ok);
    67. //qDebug()<<" server port "<<port;
    68. ui.lineEditServerStatus->setText("server started");
    69.  
    70. QApplication::processEvents();
    71.  
    72. tcpipThread tcpipThreadStart(ui, port);
    73. tcpipThreadStart.start();
    74. // tcpipThreadStart.wait(ULONG_MAX);
    75.  
    76. }
    77. void tcpip::StartTCPClient()
    78. {
    79. ui.listWidgetClient->addItem(QString("client StartTCPClient"));
    80. bool ok = true;
    81. QString qstr = ui.lineEditTCPIPServerPortClient->text();
    82.  
    83. //QApplication::processEvents();
    84. ushort port = qstr.toInt(&ok);
    85. //qDebug()<<"client port = "<<port;
    86. tcpip_client* p_client = new tcpip_client((int)19999,port,FALSE, ui);
    87.  
    88. str_client(p_client, ui); /* process the request */
    89. close();
    90. }
    91. //
    92. #define MAXLINE 512
    93.  
    94. // str_client is the client processing program
    95. // particular to the application and depends on
    96. // what the server is doing
    97. void tcpip::str_client(tcpip_client* tcpip_x, Ui::tcpipClass ui)
    98. {
    99. int n;
    100. char sendline[MAXLINE], recvline[MAXLINE + 1];
    101. bool done=FALSE;
    102. while (!done)
    103. {
    104. cout<<"enter keyboard string"<<endl;
    105. cin.getline(sendline,256);
    106. n = strlen(sendline);
    107. if(n==0) break;
    108. sendline[n] = '\n'; /* newline terminate */
    109. sendline[n+1] = 0; /* newline terminate */
    110. n++;
    111. // use our client object to write to the server
    112. ui.listWidgetClient->addItem(QString("client constructorstr_client"));
    113. tcpip_x->tcp_write(sendline,n);
    114. cout<<"sendline:"<<sendline<<endl;
    115. /*
    116.   * Now read a line from the socket and write it to
    117.   * our standard output.
    118.   */
    119.  
    120. n = tcpip_x->tcp_read(recvline);
    121. recvline[n] = '\n'; /* null terminate */
    122. recvline[n+1] = 0; /* null terminate */
    123. n++;
    124. cout<<"bytes received "<<n;
    125. cout<<"client received:echo = "<<recvline<<endl;
    126. }
    127.  
    128. }
    129. void tcpip::currChanged(QWidget*){};
    130.  
    131. void tcpipThread::start()
    132. {
    133. tcpip_server* p_serv = new tcpip_server((int)19999,port,tcpip_server::str_echo, ui);
    134. qDebug()<<"oops...back from CTOR";
    135. delete p_serv;
    136. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 3rd December 2009 at 12:02.

Similar Threads

  1. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13
  2. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 02:25
  3. Replies: 13
    Last Post: 15th December 2006, 12:52

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.