Results 1 to 3 of 3

Thread: Class member reference

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Class member reference

    Thanks to the folks who have already helped me along with this, but I am still having a little trouble referencing class members.

    Here's the relevant part of the header:
    Qt Code:
    1. class QTableView;
    2.  
    3. private:
    4. QTableView *view;
    To copy to clipboard, switch view to plain text mode 

    And part of the cpp:

    Qt Code:
    1. model = new QSqlTableModel();
    2. view = new QTableView();
    3.  
    4. model->setTable("log");
    5. model->select();
    6.  
    7. QTableView *view = new QTableView;
    8. view->setModel(model);
    9. view->setMinimumSize(1200,100);
    10. view->move(35,80);
    11. view->setSortingEnabled(TRUE);
    12. QHeaderView *header = view->horizontalHeader();
    13. header->setMovable(TRUE);
    14. view->show();
    To copy to clipboard, switch view to plain text mode 

    All of that works fine. Problem comes when I try to use model-> or view->
    in a local function. No errors, but no results. Like trying to set the view title or apply a filter to the model. Both of these work fine if the code for them is right after the code shown above, but when in a local function like this, they have no effect.

    Qt Code:
    1. checkPrefs();
    2.  
    3. void MainWindow::checkPrefs() {
    4. view->setWindowTitle("My Log");
    5. MainWindow::model->setFilter("call = 'k0zav'");
    6. }
    To copy to clipboard, switch view to plain text mode 

    And if I check the model assigned to the view in the checkPrefs code, it comes back empty.

    So, what am I doing wrong here?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Class member reference

    You have local variables that shadow the ones declared in the class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    waynew (20th December 2009)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default

    Thanks for the reply. I understand what you are saying, conceptually, but not sure where. Do you mean lines 1 and 2 of the first lines in cpp?
    Without those, it crashes when checkPrefs is called.
    So I'm confused.

    Ok Wysota - I got it now.
    Just removed the *model and *view lines and it is working perfectly.
    Thanks for your help!
    Last edited by wysota; 20th December 2009 at 10:03.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 15:22
  2. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 09:34
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 18:33
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 15:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 20:15

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.