Answer the question
In order to leave comments, you need to log in
How to call a main class method from another class?
There is a method Class::method();
How can I call it from another Class2 class? Declared the header class.h in the second class, but still writes that Class wasn't declared.
Tried passing a pointer to the Class2 constructor like Class *pp. When declaring a class, I entered this. Still an error occurs. What am I doing wrong?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Again, without having studied the C ++ base and the Qt documentation, you are trying to solve the task at hand. The C++ programming language is not the language where this approach can be used. You either know the basics well, or you don't know anything at all.
You need to take advantage of data exchange between classes. This can be done in various ways: getters-setters, double inheritance, passing a pointer, a signal-slot system, a common class for data exchange, static methods, etc.
There are many examples on the Internet:
easy-qt.blogspot.ru/2012 /10/1.html
www.cyberforum.ru/qt/thread548059.html
fkn.ktu10.com/?q=node/3021
www.prog.org.ru/topic_19557_0.html
And you have a rather strange approach. The form should query the boolean class, not the other way around. That is, your non-GUI-class should not contain anything and pull Qt's. Suddenly it will have to be moved to a separate library that has nothing to do with GUI and Qt?
I highly recommend looking at the sample applications that come with Qt. There you will find all the answers to your questions and methods for building the right application architecture.
@l2p In that case, @kachsheev was right. Here is an example:
class MyClass
{
public:
void MethodFromClass1() { //метод для теста
cout << 666;
}
};
class MyClass2 : public MyClass
{
public:
void MethodFromClass2() {
MethodFromClass1(); //вызов метода из производного класса
}
};
int main()
{
MyClass2 obj;
obj.MethodFromClass2();
return 0;
}
class.h:
class Class
{
public:
void mathod();
}
class Class2
{
public:
void method2()
{
Class class1;
class1.method();
};
}
#include "Class2.h"
int main()
{
Class2 class2;
class2.method2();
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question