Results 1 to 14 of 14

Thread: QProcess again ..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QProcess again ..

    it works fine now:

    Qt Code:
    1. ServerMainWindow::ServerMainWindow(QWidget* parent, const char* name)
    2. : MainWindowBase(parent, name),
    3. m_server(0)
    4. {
    5. m_clients.setAutoDelete(true);
    6.  
    7.  
    8. proc = new QProcess(this);
    9.  
    10. proc->addArgument("ipconfig");
    11. proc->addArgument("-all");
    12.  
    13.  
    14. QObject::connect(proc,SIGNAL(readyReadStdout()),this,SLOT(readFromStdout()));
    15. QObject::connect(m_start, SIGNAL(clicked()), this, SLOT(slotStartClicked()));
    16. QObject::connect(m_stop, SIGNAL(clicked()), this, SLOT(slotStopClicked()));
    17. proc->start();
    18. }
    19.  
    20. ////////////////////////////////////////////////////////////////////////////////
    21.  
    22. void ServerMainWindow::readFromStdout(){
    23. // QByteArray data = proc->readStdout();
    24. QString data = proc->readStdout();
    25. textEdit1->setText(data);
    26. sendToClients(data);
    27. }
    28. ////////////////////////////////////////////////////////////////////////////////
    29.  
    30. ServerMainWindow::~ServerMainWindow()
    31. {
    32. slotStopClicked();
    33. }
    34.  
    35. ////////////////////////////////////////////////////////////////////////////////
    36.  
    37. void ServerMainWindow::sendToClients(const QString& text)
    38. {
    39. if (text.isNull()) return;
    40.  
    41.  
    42. // iterate over all clients and send them the text
    43. QPtrDictIterator<Client> iter(m_clients);
    44. for (; iter.current() != 0; ++iter)
    45. {
    46. QSocket* sock = iter.current()->socket();
    47. QTextStream stream(sock);
    48. stream << text;
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 


    but still my client doesn't recive stdout from ipconfig
    function sendToClients(data); should send QString to void ServerMainWindow::sendToClients(const QString& text)

    is the function sendToClients(const QString& text) correct? or could be there some issue in the client application?

    client function that recieves data from server app is:
    Qt Code:
    1. void ClientMainWindow::slotRead()
    2. {
    3. QString text;
    4. while (m_socket->canReadLine())
    5. text += m_socket->readLine();
    6.  
    7. if (!text.isNull())
    8. appendText(text, Output);
    9. }
    10.  
    11.  
    12. where
    13.  
    14.  
    15.  
    16. void ClientMainWindow::appendText(const QString& text, Mode mode)
    17. {
    18. switch (mode)
    19. {
    20. case System:
    21. m_textEdit->setColor(Qt::blue);
    22. break;
    23.  
    24. case Error:
    25. m_textEdit->setColor(Qt::red);
    26. break;
    27.  
    28. default:
    29. m_textEdit->setColor(Qt::black);
    30. break;
    31. }
    32.  
    33. m_textEdit->append(text);
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QProcess again ..

    OK I found it already
    Thank you jacek 4 your time

Similar Threads

  1. QProcess +standard error + windows
    By antonio.r.tome in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2006, 14:58
  2. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 14:11
  3. Replies: 4
    Last Post: 13th February 2006, 11:35
  4. speed up qprocess readstdout
    By kooshball in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2006, 09:42
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15: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.