Results 1 to 4 of 4

Thread: Qt isn't recognizing object

  1. #1
    Join Date
    May 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Qt isn't recognizing object

    Noob question, I know, I'm still learning etc.

    I've declared some objects in my mainwindow constructor but when I try to work with them in a slot they doesn't work
    Qt Code:
    1. ui(new Ui::MainWindow)
    2. {
    3. ui->setupUi(this);
    4. ledek led[3][9];
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::on_checkBox_1_stateChanged (int arg1)
    2. {
    3. for(asd=0;asd<3;asd++)
    4. {
    5. led[asd][1].szam=(arg1==0 ? 0:1)
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    Led was not declared in this scope.

  2. #2
    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: Qt isn't recognizing object

    In line 4 you are defining a local stack variable
    Stack variables "end" when the scope they are define in ends, in this case when the contructor ends.

    If you need variables to exist during the object life time, you need to use member variables.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    skipper (9th February 2016)

  4. #3
    Join Date
    May 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qt isn't recognizing object

    ledek is the class and led[3][9] is an array of objects, so how do I make it a member variable? I'm a bit confused, could you give me an example?

  5. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Qt isn't recognizing object

    Same way you may any variable a member variable. Declare it in the class definition (header file), typically as a private variable. Initialize using a constructor initializer list or constructor, etc.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. emit signal and recognizing in a different class
    By salmanmanekia in forum Newbie
    Replies: 11
    Last Post: 18th October 2011, 08:19
  2. Replies: 0
    Last Post: 11th November 2010, 13:05
  3. Recognizing file or directory
    By AD in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2008, 16:18
  4. QTcpSocket not recognizing disconnect
    By jimroos in forum Qt Programming
    Replies: 3
    Last Post: 6th September 2007, 15:31
  5. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13

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.