Results 1 to 6 of 6

Thread: Another scope problem!

  1. #1
    Join Date
    Aug 2014
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Another scope problem!

    In the following code segment from dialog.cpp, the push button saveFolderPB gives the error "not declared in this scope". WHY? I have no idea. I have a simple dialog with a few buttons using on_object_triger private slots, which all work correctly. In the slot shown in the code snipped all I am doing is trying to enable another push button. Why is the button widget not declared in scope? It is public in ui_dialog.h, which is included as shown in the snipped - and it was put there by QCreator. I thought all class member variables are accessible by all class non-static member methods.
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include <QFileDialog>
    4. #include <iostream>
    5. ....
    6.  
    7. void Dialog::on_QFXSourcePB_pressed()
    8. {
    9. // Display file selection dialog.
    10. QString selfilter = "QFX (*.qfx)";
    11. QString inFileName = QFileDialog::getOpenFileName(
    12. this,
    13. "Select .qfx file.",
    14. "C:\\users\\Mike\\Desktop",
    15. "All files (*.*);; QFX (*.qfx)", &selfilter);
    16.  
    17. if (!inFileName.isEmpty()){
    18. saveFolderPB.setEnabled(); // NOT DECLARED IN THIS SCOPE !!
    19. QFXreader reader;
    20. reader.readQFX(inFileName, qfxInfo, qifTL);
    21. }
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Another scope problem!

    It may be public there, but you still have to specify where it is. Normally Qt gives you the ui-> namespace that will give you access to your ui elements like this:
    Qt Code:
    1. ui->whateverWidget
    To copy to clipboard, switch view to plain text mode 

    For this to work you should find (automatically created)

    Before your class definition (here it is my MainWindow) in the header file:
    Qt Code:
    1. namespace Ui {
    2. class YourClass;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Private in the header:
    Qt Code:
    1. Ui::YourClass *ui;
    To copy to clipboard, switch view to plain text mode 

    In the .cpp the constructor should call
    Qt Code:
    1. ui(new Ui::YourClass)
    To copy to clipboard, switch view to plain text mode 
    and before acually using the ui you need a
    Qt Code:
    1. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    All of this should have been done automatically when using the Designer. Just use the ui-> thingy :-)

    HTH
    Sebastian

  3. #3
    Join Date
    Aug 2014
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Another scope problem!

    sedi, thanks for the reply. When I worked with Designer years ago, I was not concerned with any ui namespace that I can remember. And yes, your right QCreator should have put in the namespace declaration.
    Mike

  4. #4
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Another scope problem!

    According to this thread of yours, it seems to actually have done so:

    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include <QList>
    6.  
    7. namespace Ui {
    8. class Dialog;
    9. }
    10.  
    11. class Dialog : public QDialog
    12. {
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Aug 2014
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Another scope problem!

    Yea, I noticed that just after my last reply. I'll just remember to use the ui-> thingy!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Another scope problem!

    Quote Originally Posted by mikea View Post
    sedi, thanks for the reply. When I worked with Designer years ago, I was not concerned with any ui namespace that I can remember.
    You were probably inheriting from the generated class

    Quote Originally Posted by mikea View Post
    And yes, your right QCreator should have put in the namespace declaration.
    That's what it does when you create a "Designer form class", i.e. it creates both the form and the class using it.

    Cheers,
    _

Similar Threads

  1. CONFIG(release) scope problem
    By jonks in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2010, 17:30
  2. out of scope
    By mmm286 in forum Newbie
    Replies: 3
    Last Post: 23rd October 2009, 12:23
  3. Scope problem maybe?
    By Nefastious in forum Newbie
    Replies: 6
    Last Post: 17th September 2009, 00:00
  4. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 20:44
  5. QT4 scope problem
    By the_bis in forum Newbie
    Replies: 5
    Last Post: 30th January 2007, 00:01

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.