February 15, 2011

denya denya
Lab Rat
6 posts

[Moved] QT and data input in ubuntu terminal

Page  
1

When I start a simple program that needs to input data in terminal (Ubuntu) – I can`t do it. In the console window i can input everything but the programm doesn`t respond.
Please tell me what is wrong?

25 replies

February 15, 2011

Volker Volker
Robot Herder
5428 posts

Probably your code is wrong.

Sorry, that’s much too less information to give you a reasonable answer. You can provide us the source code for a

  • short
  • complete
  • compilable
  • runnable

program that demonstrates us the problem and we’ll have a look.

February 15, 2011

denya denya
Lab Rat
6 posts

Here is the code:

  1. #include <iostream>
  2. using namespace std;
  3. #include <cctype>
  4.  
  5. int fuct (int);
  6.  
  7. int main()
  8. {
  9.         int n;
  10.  
  11.         cout << "Input number: ";
  12.         while (cin >> n)
  13.         {
  14.                 int fk = fuct (n);
  15.                 cout << "\nFactorial: " << fk << "\n";
  16.                 cout << "Input number: ";
  17.         }
  18.  
  19.         return 0;
  20. }
  21.  
  22. int fuct (int n)
  23. {
  24.         if (n == 0) return 1;
  25.                 else if (n == 1) return 1;
  26.                         else return n * fuct(n-1);
  27. }

[EDIT: code formatting, please use @-tags, Volker]

February 15, 2011

Tobias Hunger Tobias Hunger
Mad Scientist
3149 posts

How does this code relate to Qt?

February 15, 2011

denya denya
Lab Rat
6 posts

Sorry, the code was displayed wrong in the previous post:

  1. #include <iostream>
  2. using namespace std;
  3. #include <cctype>
  4.  
  5. int fuct (int);
  6.  
  7. int main()
  8. {
  9.         int n;
  10.  
  11.         cout << "Input number: ";
  12.         while (cin >> n)
  13.         {
  14.                 int fk = fuct (n);
  15.                 cout << "\nFactorial: " << fk << "\n";
  16.                 cout << "Input number: ";
  17.         }
  18.  
  19.         return 0;
  20. }
  21.  
  22. int fuct (int n)
  23. {
  24.         if (n == 0) return 1;
  25.                 else if (n == 1) return 1;
  26.                         else return n * fuct(n-1);
  27. }

[EDIT: code formatting, Volker]

February 15, 2011

denya denya
Lab Rat
6 posts

so, if it has not relation to Qt it will not work properly?

February 15, 2011

Volker Volker
Robot Herder
5428 posts

Nothing is wrong, it works for me.

Also this has nothing to do with Qt.

February 15, 2011

denya denya
Lab Rat
6 posts

I have understood about Qt, but input data doesn`t work in the console:

————————————————————————————————————-
Launching /home/denis/tutorial-build-desktop/tutorial…
Input number: 1

1
2
2w

d
c
————————————————————————————————————-

I can input everything and the programm doesn`t have any reaction.

February 15, 2011

denya denya
Lab Rat
6 posts

The debugger wrote:

&“warning: GDB: Failed to set controlling terminal: \320\235\320\265\320\264\320\276\320\277\321\203\321\201\321\202\320\270\320\274\321\213\320\271 \320\260\321\200\320\263\321\203\320\274\320\265\320\275\321\202\n”

February 15, 2011

Volker Volker
Robot Herder
5428 posts

If you have a console application that reads from the console then please do start it on the console and neither in a debugger nor in your IDE.

EDIT: PS: If you had provided us that information before, you would have got an answer.

February 15, 2011

Volker Volker
Robot Herder
5428 posts

Moved to tools forum, as it seems to be an issue with how to use Qt Creator properly.

April 9, 2011

mzimmers mzimmers
Ant Farmer
524 posts

Hi, Volker –

So, do I understand from your post above that if a program needs console input, we can’t/shouldn’t launch it from Creator?

April 9, 2011

Volker Volker
Robot Herder
5428 posts

At least it’s hard to debug, because you have no means to input your data (at least I’m not aware of one), so your program hangs once it tries to read from stdin.

April 9, 2011

mzimmers mzimmers
Ant Farmer
524 posts

OK, thanks. I suppose that, given that Qt is a GUI development system, this is reasonable, though it may surprise some people who come from a more conventional IDE like Eclipse.

Is there at least a way to launch the terminal from Qt? Some minor level of integration would make it a little easier.

EDIT: let me rephrase that: there does appear to be some kind of terminal integration (though I can’t get it to work for me); can one launch an app to terminal from Qt while still controlling the app through the Qt debugger? That would be slick.

April 9, 2011

Volker Volker
Robot Herder
5428 posts

It’s not a problem of GUI or console development. You can have console input on a GUI program too :-)

Ah, seems that I was wrong!

In the run settings (project view of Creator) you can check a checkbox “run in terminal”, this might be what you want. It’s a bit cumbersome on the mac though (I remember you being on OS X, right?). You must set the terminal application on the mac to

/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

(Settings, Environment, first tab)

April 9, 2011

mzimmers mzimmers
Ant Farmer
524 posts

That sure seems like it should work, doesn’t it? But, when I try to start a debug session, I get an error message at launch, saying it can’t start the terminal emulator ‘/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal’. Dunno…

Page  
1

  ‹‹ [Moved] Qt4 Designer not easy to use      Qt Creator Todo/Task Plugin ››

You must log in to post a reply. Not a member yet? Register here!