Results 1 to 8 of 8

Thread: Write to QProcess

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2017
    Posts
    12
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Write to QProcess

    I'm developing a UI with Qt Creator that controls an OPC Server.

    Check Input Function OPC Server:
    Qt Code:
    1. void runUserInterface()
    2. {
    3. // we have an endless loop waiting for a keyboard input
    4. bool end = false;
    5. _tprintf(_T("The server is running.\n"));
    6. usage();
    7.  
    8. while(!end)
    9. {
    10. // variables for input purposes
    11.  
    12. tstring input = _T("");
    13.  
    14. cin >> input;
    15.  
    16. if (input == _T("x") || input == _T("q") || input == _T("X") || input == _T("Q"))
    17. {
    18. // exit if one of the four exit characters is hit
    19. _tprintf(_T("Shutdown\n"));
    20. end = true;
    21. }
    22. if (input == _T("s"))
    23. {
    24. // exit if one of the four exit characters is hit
    25. _tprintf(_T("Shutdown\n"));
    26. end = true;
    27. }
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    When I run it in Visual Studio, it's working and the Server shuts down. When I write to the Process in Qt Creator, the UI stops working.

    Source Code from UI
    Qt Code:
    1. #include "control_window.h"
    2. #include "ui_control_window.h"
    3. #include "configuration_window.h"
    4.  
    5. #include "configuration_window.cpp"
    6. #include <QProcess>
    7. #include <QWidget>
    8.  
    9. #define CMD_EXIT "q"
    10.  
    11. control_window::control_window(QWidget *parent) :
    12. QWidget(parent),
    13. ui(new Ui::control_window)
    14. {
    15. ui->setupUi(this);
    16. }
    17.  
    18. control_window::~control_window()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void control_window::on_control_window_Exit_clicked()
    24. {
    25. m_opc_ua_server->write(CMD_EXIT);
    26. m_opc_ua_server->waitForBytesWritten();
    27. }
    To copy to clipboard, switch view to plain text mode 
    The UI just crashes when on_control_window_Exit_clicked() is triggered, the OPC Server is still running though.
    It also crashes when I use m_opc_ua_server->terminate();

    I think the problem is in the UI, I made a small test program and the same error occurs.

    test program:
    Qt Code:
    1. #include "stdafx.h"
    2. #include <string>
    3. #include <iostream>
    4.  
    5. class MyClass
    6. {
    7. public:
    8. MyClass();
    9. ~MyClass();
    10. void checkinput();
    11.  
    12. private:
    13.  
    14. };
    15.  
    16. MyClass::MyClass()
    17. {
    18. }
    19.  
    20. MyClass::~MyClass()
    21. {
    22. }
    23.  
    24. void MyClass::checkinput()
    25. {
    26. }
    27.  
    28. string input = "";
    29.  
    30. void checkinput()
    31. {
    32. cin >> input;
    33. }
    34.  
    35. int main()
    36. {
    37. bool end = false;
    38. while (!end)
    39. {
    40. checkinput();
    41. if (input == "j")
    42. {
    43. end = true;
    44. }
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 
    What's wrong?
    Last edited by anda_skoa; 3rd March 2017 at 07:52. Reason: missing [code] tags

Similar Threads

  1. How to send cursor keys using QProcess write?
    By clive in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2012, 00:58
  2. Write to QProcess from stdin
    By rajji_saini in forum Newbie
    Replies: 2
    Last Post: 24th October 2011, 18:45
  3. Replies: 7
    Last Post: 13th September 2011, 13:15
  4. QProcess plink.exe - how to process->write
    By Phalanx in forum Newbie
    Replies: 1
    Last Post: 25th February 2011, 09:40
  5. recieving QProcess::write data
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2008, 12:18

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.