Results 1 to 5 of 5

Thread: static member function

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question static member function

    hi qt gurus..it's actually not my first time to present this problem although I had to redirect since I was going off board..anyway, I'm getting confused with my OOP. I'm not really used with having 2 .h files. But here in qt, I have to make my own .h and the other ui.h. here's the link to my previous post: Button-Controlled Loop Thread

    Now, I checked my codes specifically the 2 header files that I have..According to Mr. Death I have to make a static function that would return a pointer to the object textEdit. How do I actually do it? I don't have any textEdit in the header that I made except for the ui header which was generated after I used Qt designer.

    Something even confused me more. The ui header indicates "WARNING! All changes made in this file will be lost when recompiling ui file!"

    I hope you could help me out.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: static member function

    Something even confused me more. The ui header indicates "WARNING! All changes made in this file will be lost when recompiling ui file!"
    You cannot edit the ui_.h file as they are generated based on the ui file.
    You shoul edit the looper.h and looper.cpp files. There should be a member pointer in the looper .h someething like 'm_ui' that would gave you access to the textedit, but I dont see it in your code.

  3. #3
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: static member function

    I tried to absorb the idea of having a static member function which would handle my textEdit so that I could call the function even without instance of the class I made, basicLoop.

    I recompiled and got this error message:
    C: .../looper.cpp:18: undefined reference to 'basicLoop::textEdit'

    Qt Code:
    1. class basicLoop : public QWidget, private Ui::looperDLG
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. basicLoop(QWidget *parent = 0);
    7. static void textEditAppend (int&);
    8.  
    9. public slots:
    10. void startLoop();
    11. void stopLoop();
    12.  
    13. private:
    14. static QTextEdit *textEdit;
    15. };
    To copy to clipboard, switch view to plain text mode 

    I'm not sure if I implemented the correct static data in my looper.h. I think this is the part that gives me the error. So how can I make Ui_looperDLG::textEdit be my static data?

    I'm somehow getting lost with the idea of the UI header file. If I'm not on the right track, I hope you give give me some light. Thanks.
    Attached Files Attached Files

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: static member function

    you have to do it like this..

    Qt Code:
    1. //header
    2. class basicLoop : public QWidget, private Ui::looperDLG
    3. {
    4.  
    5. private:
    6. static QTextEdit* te;//name it different than ui header
    7. public:
    8. static QTextEdit* getTextEdit();
    9. }
    10.  
    11. //cpp
    12. #include <QtGui>
    13. #include "looper.h"
    14.  
    15. bool stop;
    16. void mainLoop();
    17.  
    18. QTextEdit* basicLoop::te=0;//MUST do it here globaly...
    19.  
    20. basicLoop::basicLoop(QWidget *parent)
    21. {
    22. setupUi(this); // this sets up GUI
    23.  
    24. te= textEdit//This textEdit is inherited from ui header
    25. }
    26.  
    27. QTextEdit* basicLoop::gettextEdit()
    28. {
    29. return te;
    30. }
    To copy to clipboard, switch view to plain text mode 
    now you can call the basicloop::gettextEdit() in your mainloop()...

    this is not the best solution.. coz this assumes that you are using only single instance of basicloop... becoz everytime a new object of basicloop is created the textedit will change.. if you only use one instance of basicloop.. make it a singleton class.

  5. The following user says thank you to nish for this useful post:

    freekill (29th July 2009)

  6. #5
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: static member function

    Thanks finally got it working.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.