Results 1 to 3 of 3

Thread: Problem with scope of variables

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2016
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Problem with scope of variables

    In the following code the compiler says that the variable "currentRow" is unused in "on_pushButton_2_clicked()" and not declared in "on_pushButton_clicked()". I've tried declaring "int currentRow" in every place and in every way I can think of and nothing works. Seems like a trivial issue, but I'm stumped.
    Qt Code:
    1. void Dialog::on_pushButton_2_clicked()
    2. {
    3. // declare and set variables
    4. QMessageBox::information(this, "Settings","Setting Row and Column");
    5. int currentRow = 3;
    6. int currentCol = 5;
    7. }
    8.  
    9. void Dialog::on_pushButton_clicked()
    10. {
    11. // view variable values
    12. QString nmbr = QString::number(currentRow);
    13. QMessageBox::information(this,"info","currentRow = " + nmbr);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 6th June 2016 at 18:48. Reason: missing [code] tags

Similar Threads

  1. C++ Scope Issue / Stray Member Variables
    By 0backbone0 in forum General Programming
    Replies: 5
    Last Post: 23rd August 2015, 13:20
  2. Another scope problem!
    By mikea in forum Newbie
    Replies: 5
    Last Post: 5th October 2014, 07:25
  3. Scope problem maybe?
    By Nefastious in forum Newbie
    Replies: 6
    Last Post: 16th September 2009, 23:00
  4. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  5. QT4 scope problem
    By the_bis in forum Newbie
    Replies: 5
    Last Post: 29th January 2007, 23:01

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.