PDA

View Full Version : out of scope



mmm286
23rd October 2009, 10:20
Hi,

I can't understand why it says me in the debugger the error:
src/mainwindowimpl.cpp:449: error: ‘HoraPrimero’ no se declaró en este ámbito
src/mainwindowimpl.cpp:449: error: 'HoraPrimero' was not declared in this scope

In my code I have:



if ( minutoActual >= "30" ) {

QTime n(horaActual.toInt(), 30, 0);
......
.....
QString HoraPrimero = n.toString();
....
}
else
{
.............
}

QString HoraPriCol = HoraPrimero.mid(0, 2);

Ginsengelf
23rd October 2009, 10:31
Hi, are you sure that you don't have closing braces for the if (...)?

Ginsengelf

edit: is it correct that you don't close the if block before the else?

mmm286
23rd October 2009, 11:02
Sorry I have a mistake when I paste the code. I've updated the first post with the good code.

Any help?
Many thanks!

jano_alex_es
23rd October 2009, 11:23
Because "HolaPrimero" is a local variable of the if.

You can't declare a variable inside a if sentence and use it outside. Read where it says "Variables locales y globales " (http://www.modelo.edu.mx/univ/virtech/prograc/cplus2.htm)

This will work:



QString HolaPrimero;
if ( minutoActual >= "30" ) {

QTime n(horaActual.toInt(), 30, 0);
......
.....
HoraPrimero = n.toString();
....
}
else
{
.............
}

QString HoraPriCol = HoraPrimero.mid(0, 2);