-3

I'm new both to QT development, and std libraries.

At this moment I'm trying to create a simple console application, although it's simple, it must be cross platform. It must work with Linux, Windows and android.

While I'm quite used with using std::cout and std::cin to read and write to the console. I'm trying to figure out the same thing with QT libraries.

Is there any way of interacting with the user, using QT library? I cannot use std::cout and std::cin.

I've search for answers at stack overflow, but everything I find is people telling to use qDebug, but that's not what I need, I need the interaction with the user.

Ajay Soman
  • 1,631
  • 4
  • 19
  • 37
  • 2
    "I cannot use std::cout and std::cin" - why not? That's the most portable way to interact with the console. – Mike Seymour Sep 25 '12 at 13:01
  • why can't you use `std::cout` and `std::cin`, those are *the most portable* way of interacting with the user via command line that I know of.. – Nim Sep 25 '12 at 13:01
  • 1
    It's discussed [here](http://stackoverflow.com/questions/2321880/is-it-possible-to-use-cin-and-qt) – c_k Sep 25 '12 at 13:08
  • As I started with this project, I used to think it was the most portable way to interact with the console. But the staff sent this weird request of getting rid of all the std::cout and std::cin from the program. That's why I got confused – Former User of Mine Sep 25 '12 at 13:23

1 Answers1

1

Qt is mainly used for GUI's, but you can connect some Qt Classes to act like stdin and stdout.

I would read up on at least these three, and if you really don't want to use std::cin and std::cout, I would use QTextStream objects in the same way.

QDebug

QIODevice

QTextStream

Here is a chunk of code from the details documentation:

QTextStream stream(stdin);
QString line;
do {
    line = stream.readLine();
} while (!line.isNull());

QFile also has some good information in its documentation.

The only real advantage I would see with using QTextStream instead of the std library functions is to later connect it to your own built in console in your GUI (later) instead of the OS console.

Another way that I get settings and setup information from the user is using QSettings and setting the default format to INI and opening the INI file using QDesktopServices::openUrl().

phyatt
  • 18,472
  • 5
  • 61
  • 80