Results 1 to 6 of 6

Thread: how to access class member from other class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Location
    Slovakia
    Posts
    17
    Thanks
    12
    Thanked 6 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to access class member from other class

    Hello,

    this may sound like a subject for pure C++ Programming forum but I ilustrate problem on qt4/ui program, so I deciced to rather put it here.

    I have form designed in designer, it contains only treeWidget which is promoted to custom widget to add drag and drop capabilty.

    My question is how to access myAppList defined in myApp.h from qmytreewidget.cpp ? I use Qt 4.2.0-tp1 opensource, Windows 2000, mingw.

    Thanks for any suggestions.

    Whole app is zipped in attachement, most interesting parts:

    myApp.h

    Qt Code:
    1. #ifndef MYAPP_H
    2. #define MYAPP_H
    3.  
    4. #include "ui_form.h"
    5.  
    6. class myApp : public QWidget, private Ui::myAppDLG
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. myApp();
    12.  
    13. // i want to access this from qmytreewidget.cpp, line 26
    14. QStringList myAppList;
    15.  
    16. private:
    17. Ui::myAppDLG ui;
    18.  
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    qmytreewidget.cpp

    Qt Code:
    1. #include <QtGui>
    2. #include "qmytreewidget.h"
    3. #include "myApp.h"
    4.  
    5.  
    6. QMyTreeWidget::QMyTreeWidget(QWidget *parent)
    7. : QTreeWidget(parent)
    8. {
    9.  
    10. }
    11.  
    12.  
    13. bool QMyTreeWidget::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
    14. {
    15. QList <QUrl> urlList;
    16.  
    17. urlList = data->urls();
    18.  
    19. foreach(QUrl url, urlList)
    20. {
    21. item = new QTreeWidgetItem(this);
    22. item->setText(0, url.toLocalFile());
    23. // i want to access myAppList, defined in myApp.h
    24. // what is the best way to do it ?
    25. myAppList.append(url.toLocalFile()); // this of course doesn't work, just to clear what a want to do
    26. }
    27.  
    28. return true;
    29. }
    30.  
    31.  
    32. QStringList QMyTreeWidget::mimeTypes () const {
    33.  
    34. QStringList qstrList;
    35. qstrList.append("text/uri-list");
    36. return qstrList;
    37. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

Similar Threads

  1. Replies: 2
    Last Post: 4th May 2006, 19:17
  2. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 01:27
  3. const member definitions in a class ....
    By TheKedge in forum General Programming
    Replies: 5
    Last Post: 15th February 2006, 13:03

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.