Results 1 to 4 of 4

Thread: out of scope

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default out of scope

    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:
    Qt Code:
    1. if ( minutoActual >= "30" ) {
    2.  
    3. QTime n(horaActual.toInt(), 30, 0);
    4. ......
    5. .....
    6. QString HoraPrimero = n.toString();
    7. ....
    8. }
    9. else
    10. {
    11. .............
    12. }
    13.  
    14. QString HoraPriCol = HoraPrimero.mid(0, 2);
    To copy to clipboard, switch view to plain text mode 
    Last edited by mmm286; 23rd October 2009 at 11:03.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    518
    Thanks
    13
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: out of scope

    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?

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: out of scope

    Sorry I have a mistake when I paste the code. I've updated the first post with the good code.

    Any help?
    Many thanks!

  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: out of scope

    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 "

    This will work:

    Qt Code:
    1. QString HolaPrimero;
    2. if ( minutoActual >= "30" ) {
    3.  
    4. QTime n(horaActual.toInt(), 30, 0);
    5. ......
    6. .....
    7. HoraPrimero = n.toString();
    8. ....
    9. }
    10. else
    11. {
    12. .............
    13. }
    14.  
    15. QString HoraPriCol = HoraPrimero.mid(0, 2);
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to jano_alex_es for this useful post:

    mmm286 (23rd October 2009)

Similar Threads

  1. Qwt 4.2.0 compile problems
    By MarkoSan in forum Qwt
    Replies: 2
    Last Post: 28th September 2009, 09:15
  2. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  3. Just for fun game
    By vermarajeev in forum Qt-based Software
    Replies: 6
    Last Post: 13th December 2007, 21:52
  4. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  5. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.