×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    how to use this cpp code in emulator

    hi,
    i am using this code to ping 3 hosts in qt creator main file
    Code:
    #include <QtGui/QApplication>
    #include "mainwindow.h"
    #include <iostream>
    #include <stdlib.h>
    #include <windows.h>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    
    static string host[3];
    static string ping_again;
    
    
    void ping()
    {
         system("cls");        for (int i=0; i<3; i++)
         {cout << "Host: ";
         cin >> host[i];
     }
    
         for (int i=0; i<3; i++)
         {system (("ping "+host[i]).c_str());     .
             cout << endl;
            }
    
    //     cout << "Host: ";
    //     cin >> host;
    //     system (("ping "+host).c_str());
    //     cout << endl;
    
         cout << "(Y)es or (N)o\n\n";
         cout << "Ping another host: ";
         cin >> ping_again;
         if (ping_again == "Y" || ping_again == "y")
         {
         system("cls");
         ping();
         }
         else if (ping_again == "N" || ping_again == "n")
         {
         system("exit");
         }
    }
    
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        //SetConsoleTitle("Ping in C++ by TotcoS");
        ping();
        w.show();
    
        return a.exec();
    }

    as obvious this code dislplays output on the cmd nd not on the qt emulator.......
    what changes shud be done so that the same cpp code can run on the emulator....
    thanks

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: how to use this cpp code in emulator

    You have to select Simulator when you create the project with Qt SDK. And if you want to make it GUI app then you need to modify it a bit.
    Best way would be run a very simple application in Qt Simulator and see and compare your code. You know what to do then...

  3. #3
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    Re: how to use this cpp code in emulator

    got ur point but actually we hav already been working on the simulator...but since this is a pure c++ code ....i dn get how can i get the same output on the emulator......is it even possible??

    plz guide us to that...

    thanks in advance

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: how to use this cpp code in emulator

    Apparently you will need to add QTextEdit to show output, QLineEdit and optionally a button for the input. Then just replace all cin and cout with appropriate use of QTextEdit and QLineEdit.

  5. #5
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    Re: how to use this cpp code in emulator

    thanks divanov...
    but there is a problem...
    i want to do such that the output appears as follows:
    Host1: XXXXXXX
    Host2:XXXXXXXX
    Host t3=XXXXXX

    i.e. first the text edit displays Host 1 and when the user enters the address of Host 1, the text edit displays host2 and so on....
    i am using the loop as below:

    Code:
    #include <QtGui/QApplication>
    #include "tele.h"
    #include<QApplication>
    #include<QTextEdit>
    #include<QLineEdit>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
    
    
        QTextEdit le;
        le.show();
        for(int i=0;i<3;i++)
        {le.setText("Host:");
     }
    
        return a.exec();
    }

    but the statement "Host:" only shows once.....
    kindly help

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: how to use this cpp code in emulator

    Something like
    Code:
    for (int i = 0; i < 3; i++) {
            QString text = le.text();
            text = text.append("Host:\n");
            le.setText(text);
            le.update();
    }
    Or you could use append() -- I apparently missed that the first time I looked for it. Then what you append is considered a "paragraph" and you shouldn't need the "\n".

  7. #7
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    Re: how to use this cpp code in emulator

    Quote Originally Posted by danhicksbyron View Post
    Something like
    Code:
    for (int i = 0; i < 3; i++) {
            QString text = le.text();
            text = text.append("Host:\n");
            le.setText(text);
            le.update();
    }
    this piece of code is giving the following error:
    Class QTextEdit has no member named text
    Last edited by divanov; 2011-05-27 at 17:32.

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: how to use this cpp code in emulator

    Probably it can be as simple as this
    Code:
    QTextEdit edit;
    for (int i = 0; i < 3; ++i)
        edit.append("Host:\n");
    edit.show();

  9. #9
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    Re: how to use this cpp code in emulator

    Quote Originally Posted by divanov View Post
    Probably it can be as simple as this
    Code:
    QTextEdit edit;
    for (int i = 0; i < 3; ++i)
        edit.append("Host:\n");
    edit.show();
    THANKS ALOT dIVANOV
    IT WORKED!

  10. #10
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    64

    Re: how to use this cpp code in emulator

    kindly tell me that after the user has enterd ip addresses of 3 hosts in the text boxx.....how can i retrieve them and store them in some other variable????

  11. #11
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: how to use this cpp code in emulator

    Quote Originally Posted by fareenafatima View Post
    kindly tell me that after the user has enterd ip addresses of 3 hosts in the text boxx.....how can i retrieve them and store them in some other variable????
    Have you looked at any of the examples??

Similar Threads

  1. Replies: 2
    Last Post: 2011-05-12, 07:44
  2. How to use TLex8 in this case
    By alicenan88 in forum Symbian
    Replies: 6
    Last Post: 2009-11-06, 10:17
  3. could i use this code to stream voice via bluetooth
    By fevos in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2008-11-24, 17:02
  4. [defect report] carbide.cpp code formatter can't produce code conforming to s60 style
    By simo.salminen in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-10-27, 10:56
  5. Replies: 7
    Last Post: 2008-04-03, 11:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×