I've written a program in Bash and I want to port it to a QT Desktop Widget.
I've created a blank widget, and have managed to compile... so success so far!
Anyway, what I want to know is, can I have a textarea in my widget that consists of dynamic text that is updated by the code? I'm sure I can, so what is the best container for it? A frame?
If you could direct me to some tutorials, that would be great.
I am not sure exactly what you are after, but a simple label can be used like the console for output. Instead of having cout << "some text";
you would have label->setText("some text");
If I compile and run this, it prints "Hello World" in the terminal.
I wat it to print this in a text area within a QT Widget. I want the area to act like the terminal, so the next time I print to it, it gets added to the next line and everything scrolls up.
This might work better if you are getting the text from someplace other than the terminal like I have it. As it is, it takes the line the cursor is at and prints it on a new line, you have to start a new line for new text or it print the whole last line when the button is clicked. I would most likely do several things different depending on what its actual purpose, but should be a good start.
If you create a project called Terminal and replace the generated files with these it should run. main.cpp is unchanged and terminalwidget.ui will have to be pasted into a text file and renamed because you cannot edit .ui files in creator.
How do I call log_to_file("Hello World!"); from main.cpp?
Do I even have to call it from main.cpp?
To clarify:
I want to go through a block of code and log_to_file(what_I_just_did) periodically, when I've done something I want to inform the end user of.
Example...
1 2 3 4 5 6 7
code to get some hardware information...
log_to_file("hardware information gathered...");
next piece of code
log_to_file("stuff I just did...");
and on...
How do I call log_to_file("Hello World!"); from main.cpp?
You don't. You should not be adding anything to main.cpp other than what Creator generates. What I posted was not meant to be used as the main window, just a little demonstration of what would be a part of it, or as a separate dialog. If its part of the main window then there is no need to make it public since it will be a part of that class. If its a separate window or dialog then you should use signals and slots to pass the data.
In my current project I created my own dialogs instead of using the standard input and message boxes so I have 16 .h and ,cpp files along with 15 .ui files. The only thing I added to main.cpp was
to use a global style sheet imbedded in a resource file. With the exception of constructors and signals, almost everything else is private(there are 3 public functions).
Having said all that, the question is not so much how do you call a particular function, but when do you call it. Does the user do something, click a button(clicked()) or write some text(textChanged()) for example, or is there some other event that triggers when the function is called? Once you answer that question, the how becomes much clearer.