Qt Programming Language
-
@annabelle yeah, it seems to work somehow.
The output screen shows
Hello World!
.The only strang thing is: according to your code there should have been more lines of output (all the lines you added after hello world).
Are you sure the latest code is compiled and you are not running an older version of your program?
-
@aha_1980 said in Qt Programming Language:
@annabelle yeah, it seems to work somehow.
The output screen shows
Hello World!
.The only strange thing is: according to your code there should have been more lines of output (all the lines you added after hello world).
Are you sure the latest code is compiled and you are not running an older version of your program?
This time I am running the newest version of the code, and here's what I get.
-
@annabelle said in Qt Programming Language:
This time I am running the newest version of the code
Unfortunately, your latest code contains an error so it cannot be compiled. This means you are still running the old version. As a result, your output screen only contains "Hello world!" and nothing else.
Does your screenreader report the error details to you? You should have heard, "error: expected initializer before 'std'". Did you hear that?
Anyway, the error message is telling you that something is missing before 'std' on line 11. In your case, you are missing the open curly braces
{
aftermain()
. Punctuation is very important in C++ code, so you must pay careful attention to them. -
@jksh said in Qt Programming Language:
@annabelle said in Qt Programming Language:
This time I am running the newest version of the code
Unfortunately, your latest code contains an error so it cannot be compiled. This means you are still running the old version. As a result, your output screen only contains "Hello world!" and nothing else.
Does your screenreader report the error details to you? You should have heard, "error: expected initializer before 'std'". Did you hear that?
Anyway, the error message is telling you that something is missing before 'std' on line 11. In your case, you are missing the open curly braces
{
aftermain()
. Punctuation is very important in C++ code, so you must pay careful attention to them.My screenreader didn't tell me that particular error. Should I create a separate line with just an { on it?
-
@annabelle yes, please add
{
on a new line directly after the line withmain
. -
@aha_1980 said in Qt Programming Language:
@annabelle yes, please add
{
on a new line directly after the line withmain
.Here's a screenshot of a new version.
Here's where I'm confused. There's an error message in a few places that says, "cout in namespace std does not name a type.". What does this mean? Also, it seems that when I just put an { on a blank line, Codeblocks automatically puts a line below with a couple spaces, followed by a line with a single }. What's up with that, I wonder? -
@annabelle said in Qt Programming Language:
when I just put an { on a blank line, Codeblocks automatically puts a line below with a couple spaces, followed by a line with a single }. What's up with that, I wonder?
Code::Blocks was trying to be helpful. Often, when people type
{
, they also want a corresponding}
. The "couple of spaces" marks the location where people normally type in their code. (The code goes between{
and}
).However, you already had the closing
}
on your last line, so Code::Blocks ended up introducing another error. You must always check the characters that are automatically typed by your IDE. If it is not appropriate, you must remove it.Here's where I'm confused. There's an error message in a few places that says, "cout in namespace std does not name a type.". What does this mean?
This error was caused when a
}
was inserted into your code.std::cout
is not a type, so it can only be used inside a function body, between{
and}
. You will learn more about types and functions as you work through the learncpp.com tutorial. -
@jksh said in Qt Programming Language:
@annabelle said in Qt Programming Language:
when I just put an { on a blank line, Codeblocks automatically puts a line below with a couple spaces, followed by a line with a single }. What's up with that, I wonder?
Code::Blocks was trying to be helpful. Often, when people type
{
, they also want a corresponding}
. The "couple of spaces" marks the location where people normally type in their code. (The code goes between{
and}
).However, you already had the closing
}
on your last line, so Code::Blocks ended up introducing another error. You must always check the characters that are automatically typed by your IDE. If it is not appropriate, you must remove it.Here's where I'm confused. There's an error message in a few places that says, "cout in namespace std does not name a type.". What does this mean?
This error was caused when a
}
was inserted into your code.std::cout
is not a type, so it can only be used inside a function body, between{
and}
. You will learn more about types and functions as you work through the learncpp.com tutorial.Now I'm getting an error that says, "Expected Unqualified ID before Return"
And another that says, "Expected Declaration before }". What am I doing wrong? It seems I'm following the tutorial closely, but I'm stuck. -
@annabelle said in Qt Programming Language:
What am I doing wrong? It seems I'm following the tutorial closely, but I'm stuck.
Accuracy is very important in programming. You must follow the tutorial down to the nearest character.
Now I'm getting an error that says, "Expected Unqualified ID before Return"
And another that says, "Expected Declaration before }".Interpreting and fixing errors is also a very important part of programming. Always focus on the first error message, because fixing that will likely remove many subsequent errors.
Anyway, "Expected Unqualified ID before Return" is probably caused by more issues in punctuation -- for example, a
{
that doesn't have a matching}
. I can't see your latest code so I can't find the exact error.It might be easier to erase the contents of main.cpp and type them out again carefully. See if you can restore your working "Hello World" code first. After it builds and runs without errors, start making modifications.
-
@annabelle
As I said before, when you show us these screenshots we need to see the code file being compiled open in the main pane, so that we can see what you have written. You need to do that every time you want to ask a question about your code!