PDA

View Full Version : having access to members and functions of a class from its subclass



QJak
1st May 2018, 17:00
hi. i have 2 classes A and B. B is subclass into the A. B needs to access to the A members and functions. how could i do this in Qt?

d_stranz
1st May 2018, 20:06
This has nothing to do with Qt. If you are writing in C++, it is a C++ question and you should look up C++ inheritance.

If what you are asking is this kind of subclassing:



class B
{
// ...
};

class A : public B
{
// ...
};


and you mean B needs to know about methods that are defined only in A, then how is this supposed to work? If you create an instance of class B and try to cast it to "A" and use A methods, your code will probably crash when you try to call A methods because an instance of B is not an instance of A even if you force the code to treat it that way.

Maybe you should show some of your code where you are trying to do what you want, because the way I understand your question it doesn't make any sense.

QJak
2nd May 2018, 05:14
This has nothing to do with Qt. If you are writing in C++, it is a C++ question and you should look up C++ inheritance.

If what you are asking is this kind of subclassing:



class B
{
// ...
};

class A : public B
{
// ...
};


and you mean B needs to know about methods that are defined only in A, then how is this supposed to work? If you create an instance of class B and try to cast it to "A" and use A methods, your code will probably crash when you try to call A methods because an instance of B is not an instance of A even if you force the code to treat it that way.

Maybe you should show some of your code where you are trying to do what you want, because the way I understand your question it doesn't make any sense.

thanks so much d_stranz, class A is like this
class A : public QThread
if A can be a QWidget and a QThread too (class A : public QWidget and QThread), the problem can be solved.
thanks a lot help me

Lesiok
2nd May 2018, 06:49
thanks so much d_stranz, class A is like this
class A : public QThread
if A can be a QWidget and a QThread too (class A : public QWidget and QThread), the problem can be solved.
thanks a lot help me
Error. Qt GUI objects can only live in the main thread. You have a conceptual problem.

QJak
2nd May 2018, 07:24
thanks
I need to do 3 works toghether in the same time:
1- first thread does processing on gived data and showing results with GUI
2- second thread does logging (saving above data into a file)
3- third thread does waiting every 10 second and then sending a byte to GUI of the first thread for showing

please help me to do this work
thanks

Lesiok
2nd May 2018, 09:05
I think you only need two threads: main (with GUI) and worker. Worker process data, logs them to the file and sends data to GUI with signals and slots. Sending data to GUI is activated with QTimer::timeout signal with 10s period.

QJak
2nd May 2018, 15:34
thanks
before i did this by using signal and slot. but when i send a signal to two slots, the slots not working in paralell procces and first one of these slots works and after finishing this slot, the other slot starts. but i need the two slots work paralel (like thread)

Lesiok
2nd May 2018, 16:54
How do slots work in parallel if they are in one thread? If they must work in parallel then they must be in separate threads.