Results 1 to 14 of 14

Thread: Need help!!!!! Problem in running a program with the help of QProcess

  1. #1
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Linking textedit to the compiler

    I am making a qt gui application in which i have a textedit and some other gui components. I wish to link the textedit to the compiler.. Is this possible? If yes, can anyone suggest me the way to do so? Any help would be appreciable.

  2. The following 2 users say thank you to aaditya190 for this useful post:


  3. #2
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking textedit to the compiler

    Do you wish to display compiler output inside a QTextEdit? Does your app start the compiler process? In this case have a look at QProcess::readyReadStandardOutput().

  4. The following 2 users say thank you to zaphod.b for this useful post:


  5. #3
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Linking textedit to the compiler

    Yes i wish to pick the source code from one textedit and display its output in another textedit in the same application. Is there some way to implement this?

  6. The following 2 users say thank you to aaditya190 for this useful post:


  7. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking textedit to the compiler

    Yes i wish to pick the source code from one textedit and display its output in another textedit in the same application.
    Nothing to do with "Linking" or "to the compiler", just "textedit". I assume you mean a QTextEdit.

    Is there some way to implement this?
    Yes, copying the "source code", if that is what is in the text edit, to another text edit is easy.

    QTextEdit::toHtml() and QTextEdit::setHtml()
    or
    QTextEdit::toPlainText() and QTextEdit::setPlainText()
    or
    QTextEdit::document(), QTextDocument::clone(), and QTextEdit::setDocument()

    There is a small thing in every copy of Qt called Assistant. Assistant contains overview, reference documentation and examples you might find informative. Assistant is not a substitute for a basic knowledge of the programming language, compiler and other tools you are using.
    Last edited by ChrisW67; 6th December 2013 at 07:47.

  8. The following 2 users say thank you to ChrisW67 for this useful post:


  9. #5
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Linking textedit to the compiler

    I guess I couldn't explain my problem correctly. I have a textedit. I want that whatever text is written in the textedit, on the click of a button or an icon, that text goes to the compiler and compiler returns the suitable output. Is there any way to do so that I can have an interactive application just like any other Integrated Development Environment(IDE) ? Any help would be highly appreciable..

  10. The following 2 users say thank you to aaditya190 for this useful post:


  11. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking textedit to the compiler

    Zaphod.b has already told you the tools you need to do that.

  12. The following 2 users say thank you to ChrisW67 for this useful post:


  13. #7
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Link a Plain Text Edit to gcc compiler

    I have a gui application containing 2 plain text edits. Following is the image....img.jpg..

    I wish to implement a concept that the code that I write in Plain Text Edit 1, its output is displayed in Plain Text Edit 2 as mentioned in the image i.e linking the plaintextedit1 to the gcc compiler... Is this possible in qt? If yes, can anyone help me out with this??


    e.g. img1.jpg..in which plaintextedit2 is displaying the output..

    Is this possible in qt?

  14. #8
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Link a Plain Text Edit to gcc compiler

    If I understand well, you are creating an IDE. Note that the output on your pictures is not a result of mere passing a source to GCC. The compiled source needs to be linked and then run to produce some output. Therefore, you need to create a makefile and pass the makefile to make.

    A memdisk would come handy here but AFAIK Qt does not offer a memdisk. Therefore have a directory for your app and when you click the button in text edit 1:

    (1) Delete the contents of the directory.
    (2) Store the source file in the directory.
    (3) Create a makefile and store it in the directory, too.
    (4) Run make in the directory.
    (5) Pipe stdout and stderr to text edit 2.
    (6) Run the app. Have some "kill me" mechanism implemented.

    If the source file is always only one then the source file can be stored with some "standard name" so that the makefile will be always the same. This simplifies (1) - (6) considerably.

  15. The following user says thank you to Radek for this useful post:

    aaditya190 (13th January 2014)

  16. #9
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Link a Plain Text Edit to gcc compiler

    @Chrisw67 and @Stampede... I tried the code in the QProcess thread but I am unable to understand that How can I link it to the compiler? Can anyone of you please explain me stepwise as to how this can be done?? Any kind of help will be highly appreciated..

  17. #10
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Link a Plain Text Edit to gcc compiler

    @Radek : Thanku so much for this answer. Sir I am new to Qt Creator Can you please ellaborate these steps so that these will be more clear?

  18. #11
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Link a Plain Text Edit to gcc compiler

    Need Help!!!!!!!

    Sir i followed these steps and make a file which reads program written on plainTextEdit and batch file for output and i am able to reterive the output from from batch file and display it to another plainTextEdit but problem arises in case of cin and scanf statements .For example :


    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cout<<"Enter two numbers";
    cin>>a>>b;
    return 0;
    }

    When i compiled this program a batch file will open that does not contain Enter two numbers statement that means it can take the input only but does show cout/printf statements,that is creating problem because user will not be able to detect what to enter. As i understands the problem and know what to enter in a batch file suppose i enetered 2 3 so output reterive to a plainTextEdit is correct i.e Enter two numbers 2 3. But problem occurs at User Console/Command Prompt.

  19. #12
    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: Link a Plain Text Edit to gcc compiler

    Compilation does not execute a program, it just transforms source code into machine code.

    If you want to run an existing program, see QProcess.
    If you want to read what such a program writes to its standard output stream, see QProcess::readyReadStandardOutput()

    Cheers,
    _

  20. #13
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Need help!!!!! Problem in running a program with the help of QProcess

    First of all I make a file which reads program written on plainTextEdit and batch file for output and i am able to reterive the output from batch file and display it to another plainTextEdit but problem arises in case of cin and scanf statements .For example :

    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cout<<"Enter two numbers";
    cin>>a>>b;
    return 0;
    }

    When i compiled this program a batch file will open that does not contain Enter two numbers statement that means it can take the input only but does show cout/printf statements,that is creating problem because user will not be able to detect what to enter. As i understands the problem and know what to enter in a batch file suppose i enetered 2 3 so output reterive to a plainTextEdit is correct i.e Enter two numbers 2 3. But problem occurs at User Console/Command Prompt.

    Code is :
    bool MainWindow::run_file()
    {
    QMessageBox msgBox;
    QString program = "cons.bat";
    QString st="PRESS OKK!!";
    QStringList arguments;
    QProcess *proc = new QProcess(this);
    proc->startDetached(program);

    if(proc->NotRunning)
    msgBox.setText(st);
    msgBox.exec();
    proc->waitForFinished();


    display_output();
    return(true);

    }
    void MainWindow::display_output()
    {

    QFile file("out.txt");
    if(!file.open(QIODevice::ReadOnly)) {
    QMessageBox::information(0, "error", file.errorString());
    }
    //QTextStream str(&file);

    QString out_str;

    while (!file.atEnd())
    {
    out_str=file.readAll();
    }
    ui->plainTextEdit_3->clear();
    ui->plainTextEdit_3->insertPlainText(out_str);
    file.remove()
    }

    In an attached file output.png Enter two numbers is not written. As i know i have to enter two numbers then i entered 2 3 but out.txt contain the whole program output like:
    Enter two numbers 2 3

    But problem is with console window.
    Attached Images Attached Images

  21. #14
    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: Need help!!!!! Problem in running a program with the help of QProcess

    This continued opening of the same thread over and over again it really getting annoying.
    It means one of the admins has to search for the duplicate and manually merge the thread.

    Quote Originally Posted by parulkalra14 View Post
    When i compiled this program a batch file will open that does not contain Enter two numbers statement
    When you compile a program then it is not executed.
    Building and running are two very different operations.


    Quote Originally Posted by parulkalra14 View Post
    Code is :
    For the love of $DETIY use code tags.

    Quote Originally Posted by parulkalra14 View Post
    Qt Code:
    1. QProcess *proc = new QProcess(this);
    2. proc->startDetached(program);
    3.  
    4. if(proc->NotRunning)
    5. msgBox.setText(st);
    6. msgBox.exec();
    7. proc->waitForFinished();
    To copy to clipboard, switch view to plain text mode 
    That does not make any sense at all.

    QProcess::startDetached() is a static method, "proc" will be totally unaffected.

    NotRunning is a state enum value, not a public variable. That condition is always false (NotRunning == 0).

    The message box should probably not always be executed.

    Cheers,
    _

Similar Threads

  1. QProcess Problem: Program doesnt start
    By musaulker in forum Newbie
    Replies: 5
    Last Post: 1st May 2020, 00:07
  2. Replies: 0
    Last Post: 26th August 2010, 11:44
  3. Replies: 3
    Last Post: 7th August 2010, 16:12
  4. QProcess problem (Main program hangs)
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2007, 10:26
  5. Replies: 1
    Last Post: 17th May 2006, 01:23

Tags for this Thread

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.