I am new to Qt programming, I have made a simple gui with a single push button. Basically I have written a program in C++ now I want to make Gui for my project. I want to display output of all printf statement in my gui. printf statements showing their output in console but I want to add something similar to console in my gui so that whenever I call printf statement it shows its result in the gui. Could you please guide me how can I do this?
You can use a QLabel to show your output in the GUI.
Everytime you call printf, you call setText(...) instead. Now the debug text will be shown in the text label in your GUI.
You can add several QLabels for different debug outputs, if you want.
EDIT:
This could also be of interest.
use QProcess start your CLI program and use readData/writeData to get your information and put them into a QTextEdit
I have found the answer of my question, I have used textbrowser in gui and make a function which I call for printing my data in gui. I can not show the picture of my gui because I have less reputations.
here is the function that I have used for printing.
void MainWindow::print(const QString &input){
data_lab += input;//to display all data in stream
ui->label->setText(input);
ui->textBrowser->setText(data_lab);
}
and here is the call of function from main.
w.print("hellok\n");
w.print("l\n");
I hope this will help somebody like me.
Related
In the QMessageBox class in QT there are setText & setInformativeText functions,whats function of second one while it do any thing that first do?
Qt documentation says about informativeText:
On the Mac, this text appears in small system font below the text().
On other platforms, it is simply appended to the existing text.
So if you don't use your application on Mac then you can just use setText with whole text you want to display to user.
I want to create a process under QProcess with console show and acccess STDIN and STDOUT streams.
my code:
QProcess *p1 = new QProcess(this);
p1->start("cmd.exe");
if I want to show console I must use startDeatached() function, but by using this, I lost my STDIN/OUT access in my program.
if I want to have access these, I dont have my console show!!!???
help me tanx.
after more investigations, I did not find my exact answer. But I did a quick trick (kalak rashti) for this problem.
I used a QTextEdit custom class to simulate some thing behaves like console. frome this link:
https://code.google.com/p/qterminalwidget/source/browse/trunk/
with some changes for my purpose.
I created a small basic key logger in C++. For some reason when I compile and run the program with the console displayed, it will record every key stroke I make in whatever program I am using such as a browser and store it in a text file. However when I make it so that it WON'T display a console window, it will not record anything and it's just a process in the background doing nothing. Here is the link to my code: http://pastebin.com/4wqQyLJ9
The function that is giving me trouble with hiding the console, is the Stealth() function. Any suggestions, tips or hints will be helpful.
Use this function , it works for me pretty well.
ShowWindow(GetConsoleWindow(), SW_HIDE);
Instead of hiding the window after the program starts, I solved this by not
having a window to begin with. Compile with -mwindows and a window is not
created when the program starts.
Example
I would consider a Windows Service for this kind of thing if you don't need UI. Also using GetAsyncKeyState can be more stealthy if required. This C++ source might be of use...
Windows Service Keylogger
I am totally beginner in creating GUIS and I am using wxwidgets to create GUI programs in CodeBlocks. I am following this tutorials here:
http://wiki.codeblocks.org/index.php?title=WxSmith_tutorials
I have figured out how to create dialog boxes and frames. Now, I have created in C++ a program that reads information from a .txt file and calls a method displayInfo() that prints this information using cout. What I would like to do is to print this information on a single window, by clicking a button, say: "Print Information".
The part that I am finding hard, is how to call my displayInfo() method from the main.cpp of the frame, and how to display that information on a window, instead of the terminal. I tried to import the header file of my class in the main.cpp of the frame, and called displayInfo(), but I do not think this is the right way to do it.
Any help would be appreciated.
wxWidgets has some predefined dialog boxes for display small quantities of text.
See wxMessageBox description
Otherwise you will have to use a DrawText method on the panel or window.
I reccomend using a text control and then redirecting cout to the text control
Like this:
#include <iostream>
wxTextCtrl *control = new wxTextCtrl(...);
wxStreamToTextRedirector redirect(control);
// all output to cout goes into the text control until the exit from current
// scope
For more discussion of neat variations on this trick, take a look at:
http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html
Scroll down to the section titled: wxTextCtrl and C++ streams
hi im using mfc in c++,
and i need to make it modaless,
and also i need to have a function which turn on and off the gui,
which also i dont know how to do.
Thanks
Hi you need to read http://www.codeproject.com/KB/dialog/gettingmodeless.aspx and source http://msdn.microsoft.com/en-us/library/175y2765(v=VS.80).aspx
If you mean turn off gui as do not show dialogs then just dont show it use console or hidden windows