View Full Version : static member function
freekill
21st June 2009, 15:16
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 (http://www.qtcentre.org/forum/f-qt-programming-2/t-button-controlled-loop-21060.html)
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. :(
john_god
23rd June 2009, 03:34
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.
freekill
29th July 2009, 02:30
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'
class basicLoop : public QWidget, private Ui::looperDLG
{
Q_OBJECT
public:
basicLoop(QWidget *parent = 0);
static void textEditAppend (int&);
public slots:
void startLoop();
void stopLoop();
private:
static QTextEdit *textEdit;
};
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.
nish
29th July 2009, 03:00
you have to do it like this..
//header
class basicLoop : public QWidget, private Ui::looperDLG
{
private:
static QTextEdit* te;//name it different than ui header
public:
static QTextEdit* getTextEdit();
}
//cpp
#include <QtGui>
#include "looper.h"
bool stop;
void mainLoop();
QTextEdit* basicLoop::te=0;//MUST do it here globaly...
basicLoop::basicLoop(QWidget *parent)
{
setupUi(this); // this sets up GUI
te= textEdit//This textEdit is inherited from ui header
}
QTextEdit* basicLoop::gettextEdit()
{
return te;
}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.
freekill
29th July 2009, 16:23
Thanks finally got it working.:D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.