Qt Programming Language
-
@JKSH said in Qt Programming Language:
@Annabelle said in Qt Programming Language:
And now when I try to compile my "Hello World" project, I get this error.
The error says that your compiler is too old and it doesn't support the C++ 2011 standard. But I'm confused: If you're doing a basic C++ Hello World program, why is Code::Blocks trying to include Qt?
I suggest you leave Qt out for now. Just focus on learning plain C++. This way, it doesn't matter if you have an old compiler.
Now when I compile a project, with regular C++ code, here's what I got in return.
-
@Annabelle
It looks like you have progressed! It seems to be successfully rubnning yourgcc
compiler.You should open up your
Sources
folder in the left-hand pane so that we can see what file(s) you have. And perhaps open your main/only.cpp
source file into the right-hand pane so that we can see that too.The error message indicates that some
.cpp
source file has an "odd" character in it, on line #9. The sort of stray character that perhaps got in there from a mis-typing. -
@Annabelle said in Qt Programming Language:
Now when I compile a project, with regular C++ code, here's what I got in return.
The error message is "stray '\240' in program". This means your .cpp file contains a character that the compiler does not accept.
'\240' is a specially-formatted character that represents a space. It can appear when someone copies code from a website or a program like Microsoft Word, and then pastes it into their IDE.
Your compiler says that the error is in line 9. I suggest you completely erase lines 8 to 10 to get rid of the '\240' character, and then re-type those lines by hand.
-
@JKSH said in Qt Programming Language:
@Annabelle said in Qt Programming Language:
Now when I compile a project, with regular C++ code, here's what I got in return.
The error message is "stray '\240' in program". This means your .cpp file contains a character that the compiler does not accept.
'\240' is a specially-formatted character that represents a space. It can appear when someone copies code from a website or a program like Microsoft Word, and then pastes it into their IDE.
Your compiler says that the error is in line 9. I suggest you completely erase lines 8 to 10 to get rid of the '\240' character, and then re-type those lines by hand.
What's the \240 character? I'm confused on that one!
-
@Annabelle said in Qt Programming Language:
What's the \240 character? I'm confused on that one!
As I mentioned before, it is a specially-formatted character that represents a space.
There are many ways to represent text: Sighted people draw lines to represent a character, Braille users arrange dot patterns to represent a character, while computers use a number to represent a character. For example, computers represent 'A' as the number 65, 'B' as the number 66, and so on.
In computers, there are multiple ways to represent a space. \240 is one such representation. Unfortunately, this representation causes problems for your compiler when it is pasted into your IDE.
Since it is a space character, I doubt that your screenreader will read it out. Sighted people can't see the bad character on the screen either.
The easiest thing to do is to erase the offending line from your code and re-type the whole line by hand.
-
@JKSH said in Qt Programming Language:
@Annabelle said in Qt Programming Language:
What's the \240 character? I'm confused on that one!
As I mentioned before, it is a specially-formatted character that represents a space.
There are many ways to represent text: Sighted people draw lines to represent a character, Braille users arrange dot patterns to represent a character, while computers use a number to represent a character. For example, computers represent 'A' as the number 65, 'B' as the number 66, and so on.
In computers, there are multiple ways to represent a space. \240 is one such representation. Unfortunately, this representation causes problems for your compiler when it is pasted into your IDE.
Since it is a space character, I doubt that your screenreader will read it out. Sighted people can't see the bad character on the screen either.
The easiest thing to do is to erase the offending line from your code and re-type the whole line by hand.
I typed the offending line by hand, and here's what I got.
-
@Annabelle Looks good, it works
-
@Annabelle said in Qt Programming Language:
not sure Qt is a Programming Language, maybe this was already discussed, hard to know when topic has 300+ posts...
It looks like the OP never created a new thread and asked all his questions in the same one. -
@jsulm said in Qt Programming Language:
@Annabelle Looks good, it works
Cool-ee-o! So what do I do next?
-
@Annabelle: Congrats, your program is compiling and running.
However, it does not seem to output any useful yet.
So the next thing would be to actually make your program to output "Hello World!" (or any other greeting you can think of).
Good luck!
-
@aha_1980 said in Qt Programming Language:
@Annabelle: Congrats, your program is compiling and running.
However, it does not seem to output any useful yet.
So the next thing would be to actually make your program to output "Hello World!" (or any other greeting you can think of).
Good luck!
Isn't that what the line, "std::cout << "Hello, World!"; is supposed to do? I'm confused!
-
Hi @Annabelle,
Isn't that what the line, "std::cout << "Hello, World!"; is supposed to do? I'm confused!
Yes, it is. Do you have this output somewhere on your screen? In the screenshots you provided, I didn't see it.
If you already have that, then the next steps could be:
- Print "Hello World" ten times, with an upcounting number appended, like:
Hello World 1 Hello World 2 Hello World 3 ... Hello World 10
- Ask the user for his name, and greet him. That could look like this:
Hello, what's your name? Luke Nice to meet you, Luke!
That would then almost be a complete program, taking an input and providing an output. Only the data processing is missing - but we can add that later.
Regards
-
@Annabelle
Hi Annabelle.Isn't that what the line, "std::cout << "Hello, World!"; is supposed to do? I'm confused!
As I mentioned earlier, we cannot see your source code in the screenshots. You need to open your source file so that we at least can see its contents.
If you were currently editing your
.cpp
file's content, I assume you have to have it open, e.g. so your screen reader can read its content. Can you get to that state and post screenshot? -
@JonB said in Qt Programming Language:
@Annabelle
Hi Annabelle.Isn't that what the line, "std::cout << "Hello, World!"; is supposed to do? I'm confused!
As I mentioned earlier, we cannot see your source code in the screenshots. You need to open your source file so that we at least can see its contents.
If you were currently editing your
.cpp
file's content, I assume you have to have it open, e.g. so your screen reader can read its content. Can you get to that state and post screenshot?How's this?
-
@JonB said in Qt Programming Language:
@Annabelle
Hi Annabelle.Isn't that what the line, "std::cout << "Hello, World!"; is supposed to do? I'm confused!
As I mentioned earlier, we cannot see your source code in the screenshots. You need to open your source file so that we at least can see its contents.
If you were currently editing your
.cpp
file's content, I assume you have to have it open, e.g. so your screen reader can read its content. Can you get to that state and post screenshot?How about this one.
-
Hi @Annabelle,
Ok, that shows us your current main function. So far so good!
What you did there, is called hardcoding. That means, your program does greet you, but it can only great you and no one else.
Before we proceed I have an important question. When you run your program, do you get the greeting output on some window? That is an important point, because that's why we do all this programming, right?
And once that is working the task is really, to not only greet Annabelle, but also Vladimir, Julia, Rodriguez, and Sabrina, ...
To do this, you will need to get some input into your program, and store the input for further processing.
Regards
-
@Annabelle
Hi Annabelle,Yep, the latest screenshot allows us to see your code! You'll want to show us that when you have a question about your code. (At a later date if the code gets too long to show in that screen we'll have to do something else, but that can wait for now.)
A couple of points:
-
Earlier you had a compilation error, about a funny character in the code, at line #9, I believe. It seems to be compiling now, I think, so you may have dealt with that. But your lines 9, 10 and 11 are just an open-curly-brace, a blank line, and then a close-curly-brace. These do nothing, and are not useful in your code. Delete lines 9 to 11 inclusive, or replace them with a single blank line which looks nice to us (a gap between the
#include
line and the start of yourmain()
function), but you may not be fussed about blank lines/layout. -
As @aha_1980 has written, your program produces some lines of output sent to what is called "stdout" via your
std::cout
lines. This should produce some output somewhere (which can presumably be read to you), but we cannot see where that might be. The development environment you are using, known as an "IDE", is in charge of where that goes.
What we can see is that the "Build log" tab you are displaying, which shows the results of compiling, does not seem to include this output. Maybe there is a different tab at the bottom, scrolled off to the right, which has some sort of "Output" pane to send to? Or --- and it gets confusing now, I am only guessing --- the "Build log" seems to be showing that when your IDE runs your "Hello World" program it does it by passing it to an internal CodeBlocks or CodeRunner program named
cb_console_runner.exe
. Note the use of "console" there. It may be that opens up a "console" (like an output window) when it runs to display your program's output, and that might automatically go away when your program ends, I don't know.EDIT I think I now understand your IDE is Code::Blocks (not CodeRunner). I have done some brief Googling, which you may want to do, for
CodeBlocks stdout
. There are indeed various hits about "how do I get to see the output from my program from CodeBlocks".If we take, say, https://stackoverflow.com/questions/28878911/how-can-i-get-console-output-in-code-block-ide, the guy there has a similar program to yours. One thing we are told is
Click on build->run or hit Ctrl+F10 and a new CMD Window should pop up, showing you your "Hello world!".
So that tells us it does indeed need to open a separate command/output window to send the output to. Does your screenreader tell you this window gets opened or read its content?
Then the last response there says:
Please include getchar() in the function before return statement. This happens because the computer is executing your program and doesn't wait for you to see the output. Including getchar(), at the end mandates it to wait for an input & in the meanwhile you can observe your output
I did wonder if this might be the case. Because your program outputs some lines and then simply terminates, it may well be that this console output window pops up when you run your program, shows the lines, and then immediately exits. So you/your screenreader may know nothing about it. You need to cause the program to "pause" before it exists so you can examine this output window.
I'm not a C++ expert, but I believe you should try inserting the following two lines after all your
std::cout
lines and immediately before yourreturn 0;
line:std::string input; std::getline(std::cin, input);
If you do that, when you run your program I believe/hope it will not immediately run to exit as it does now. You will have to "find" that new output window and click the Enter key in it before it exits and then your program completes. Hopefully you can then get your screenreader to read it out before you press the key?
-
-
@jonb said in Qt Programming Language:
@Annabelle
Hi Annabelle,Yep, the latest screenshot allows us to see your code! You'll want to show us that when you have a question about your code. (At a later date if the code gets too long to show in that screen we'll have to do something else, but that can wait for now.)
A couple of points:
-
Earlier you had a compilation error, about a funny character in the code, at line #9, I believe. It seems to be compiling now, I think, so you may have dealt with that. But your lines 9, 10 and 11 are just an open-curly-brace, a blank line, and then a close-curly-brace. These do nothing, and are not useful in your code. Delete lines 9 to 11 inclusive, or replace them with a single blank line which looks nice to us (a gap between the
#include
line and the start of yourmain()
function), but you may not be fussed about blank lines/layout. -
As @aha_1980 has written, your program produces some lines of output sent to what is called "stdout" via your
std::cout
lines. This should produce some output somewhere (which can presumably be read to you), but we cannot see where that might be. The development environment you are using, known as an "IDE", is in charge of where that goes.
What we can see is that the "Build log" tab you are displaying, which shows the results of compiling, does not seem to include this output. Maybe there is a different tab at the bottom, scrolled off to the right, which has some sort of "Output" pane to send to? Or --- and it gets confusing now, I am only guessing --- the "Build log" seems to be showing that when your IDE runs your "Hello World" program it does it by passing it to an internal CodeBlocks or CodeRunner program named
cb_console_runner.exe
. Note the use of "console" there. It may be that opens up a "console" (like an output window) when it runs to display your program's output, and that might automatically go away when your program ends, I don't know.EDIT I think I now understand your IDE is Code::Blocks (not CodeRunner). I have done some brief Googling, which you may want to do, for
CodeBlocks stdout
. There are indeed various hits about "how do I get to see the output from my program from CodeBlocks".If we take, say, https://stackoverflow.com/questions/28878911/how-can-i-get-console-output-in-code-block-ide, the guy there has a similar program to yours. One thing we are told is
Click on build->run or hit Ctrl+F10 and a new CMD Window should pop up, showing you your "Hello world!".
So that tells us it does indeed need to open a separate command/output window to send the output to. Does your screenreader tell you this window gets opened or read its content?
Then the last response there says:
Please include getchar() in the function before return statement. This happens because the computer is executing your program and doesn't wait for you to see the output. Including getchar(), at the end mandates it to wait for an input & in the meanwhile you can observe your output
I did wonder if this might be the case. Because your program outputs some lines and then simply terminates, it may well be that this console output window pops up when you run your program, shows the lines, and then immediately exits. So you/your screenreader may know nothing about it. You need to cause the program to "pause" before it exists so you can examine this output window.
I'm not a C++ expert, but I believe you should try inserting the following two lines after all your
std::cout
lines and immediately before yourreturn 0;
line:std::string input; std::getline(std::cin, input);
If you do that, when you run your program I believe/hope it will not immediately run to exit as it does now. You will have to "find" that new output window and click the Enter key in it before it exits and then your program completes. Hopefully you can then get your screenreader to read it out before you press the key?
Here's a screenshot of what my project looks like now.
And here's a screenshot of the code.
-