How to use Qt to build a command window? - c++

I totally have no idea. Any suggestion on it? It is a command window accepting some commands like:
> Add(1, 2)
and other similars.

This is a very vague question. Since there is no built-in parser generation in Qt, you can combine boost or YACC to get parsing. Use a QInputDialog or a QTextEdit from Qt for input and display. Basically set up some events in Qt for the parsing.
Have a class extending QInputDialog storing a string cmd. This class has a parsing function which will call the right code from the entered command or report an error. Then store a set of completed commands or outputs which you display back to the user. For exact code, you need to try something, and look at some tutorials, and ask more SO questions :)
Hope this is an ok start to get your mind going.

Related

Prompt user to fill in a template?

I've never been able to find anything about this in any language, but what I want to do seems rather simple to me.
I want to prompt the user for input, but have them fill in a sort of template. Let's use a simple DD-MM-YYYY date as an example.
[█ - - ]
█ is where the user writes.
As they write, the [ and - stay where they are, with the cursor jumping past them, and hitting enter submits.
I'm not expecting anyone to write all of this for me, but cin and cout seem to be too crude a tools to do this, and so I'm wondering where I should even start, if not there.
Is there something that already does this, or at least something that gives me more control of the cursor to allow me to write it myself?
I do not want to be drawing a full-on TUI with windows and boarders and colors, so ncurses would just get in the way. I just want a single-line text field that returns the input.
EDIT: The most promising non-ncruses alternative for a helpful library seems to be Terminal.
Generally what you want is a text-based GUI library, such as ncurses. Doing console work is platform-specific, and every system has its own console API to do this. If you want to implement this yourself, you would have to examine what options does your target operating system give you in terms of console API, and build a custom solution based on that.

How to get text to display in a TextBrowser in Qt?

I am new to c++ and even newer to Qt on Linux.
Can any one give me a general idea of how to display text in a textbrowser in Qt? I can't post my code because of the seative nature of the project I am working on. All I need is a basic understanding of how to do this related to slots and signals.
My application is this: I am taking input from a CSV file, counting the ords and then displaying the number of counted words along with the line of text in an output window.
It works fine in console c++ program. However, when I code it in Qt, it does not work.
Any advise or help would be welcome.
sorry for the bad question I asked earlier.
It turns out it was a configuration issue on my part.

How to make a GUI out of a already done code in C++

I want to make a GUI . I have a code that runs, made in C++. The project is made in Visual Studio(Visual C++ 2010 Express).
The outputs now are printed in command line. I want to tranform this to be printed to a window.
Is there a way to do this in this already made project ? Or I have to make a new one.
P.S. The code is consists of many, about 20 .cpp files and about 5 .h headers.
Following my comment on your original post here's some more information that will help you get through this:
Simply turn your "cout << ...." calls (or printf if the code is
actually C) to append the text to the UI control you want the output
to be displayed in? Or you can check this "hack" out:
cplusplus.com/forum/general/27876
Now simply add a new source file to the project: call it.. MyProjectGUI.cpp
Follow this guide here to setup the window on your project:
http://msdn.microsoft.com/en-us/library/bb384843.aspx
Then go through the rest of your code (or use the hack mentioned above or some kind of pipe to redirect your output (probably a lot! more complicated than the following method) and simply replace your cout << / printf calls with something like what's detailed in here: http://www.programmersheaven.com/mb/windows/105327/105327/appending-text-to-edit-control/
You'll find the basic idea of your modifications to be along these lines:
Create a simple window
Add a new edit field to the window (http://en.wikibooks.org/wiki/Windows_Programming/User_Interface_Controls and http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx)
Replace all console printing calls with a call to your append function for the edit box in the GUI
Best of luck with this (I might write up some code if I'm bothered but don't count on it -> no time. You should be able to figure it out with what I've posted though)
You dont have to do another project. It is enough to include headers and add libraries to linker. You should try a QT which is portable, well written and easy to learn. My one advice is to stay as portable as possible, in example you can create a makefile for your project so add new libraries will be a quiet easy job and not related to IDE . Dont stick to one environment.

How to keep the terminal from scrolling

I am writing a simple program in C++ to be run in a terminal window. I would like the output text to be locked in position on the screen. Instead of each new line appearing at the bottom of the screen and pushing everything up, I would like to be able to change a line of text or some characters in a line of text, while keeping other lines above and below it static. I know I have seen this done in terminal, and I believe it was done with C++, but I can't find any documentation on it. I cannot even think of what this type of display might be called. My google fu has failed me; please help. If you can tell me what commands/library to use, that would be great, but even being able to tell me what commands accomplish this in a programming language other than C++ would give me more to go on than I have now.
You want ncurses, a library for displaying text on a terminal.
If you are programming for Microsoft Windows, try googling for Win32 Console Functions.

how to write and read a text to and from a LineEdit using QT Creator?

I am working with QT Creator. I have a form that contains a push button and an Line Edit. I would like to print a string that i give programatically in this LineEdit.Secondly I would also like to the from the LineBox a string that I fill in and print it using QMessageBox.
How to do it? Need some help. I don't know how to access the displayText() to write and read from a LineEdit.
I would like to specify that I put the push button and the lineedit on the Form using drag and drop.
I am working in c++ under Ubuntu
Appreciate.
You use QLineEdit::setText() to change the text and QLineEdit::text() to read.
Your questions are very basic and show a clear lack of studying the documentation and experimenting thing yourself. Qt is one of the better documented frameworks out there and with lots of examples. Please take your time to go through them.