I am writing this code against my will - the teacher's requirement, I apologize in advance for its absurdity.

There is some base class that inherits from the QObject class.

The base class, in turn, inherits another class, say, game

When attempting to emit a signal, the following errors occur.

D: \ code \ untitled18 \ game.cpp: 32: error:

file not found collect2.exe: -1: error: ld returned 1 exit status

I attach the base code:

#ifndef BASE_H #define BASE_H #include <QObject> class base : public QObject { Q_OBJECT public: explicit base(QObject *parent = 0); void show_tree(int level); signals: public slots: }; #endif // BASE_H #include "base.h" #include <iostream> using std::cout; base::base(QObject *parent) : QObject(parent) { } void base::show_tree(int level) { QList <base *> list; // лист дочерних объектов QString str; // буфферная строка, обеспечивающая совместимость cout и QString base * object; // Создание указателя на объект базового класса for ( int i = 0; i < level; i++ ) // Задание отступа в соответствии с уровнем заданного объекта { cout << "-"; // Задание отступа с помощью соответствующего количества пробелов } str=this->objectName(); cout << str.toStdString() << "\n"; // Вывод имени объекта list = this->findChildren <base*>(); //выгрузка листа дочерних объектов if ( !list.isEmpty( ) ) // Проверка наличия дочерних объектов { QList <base *>::iterator it_child; it_child=list.begin(); while ( it_child != list.end( ) ) // Обход дочерних элементов, пока все не будут пройдены { object = * it_child; // Задание соответствующему объекту одного из дочерних ( *object ).show_tree( level + 1 ); // Построение следующего уровня дерева it_child++; // Задание следующего объекта } } } 

code user_input ():

 #ifndef USER_INPUT_H #define USER_INPUT_H #include <base.h> class user_input: public base { public: user_input(); void input_attempts(); void execute(); void new_attempt(); signals: void attempt_set(int attempts); void attempt_stated(QChar attempt); }; #endif // USER_INPUT_H #include "user_input.h" #include <iostream> #include <QTextStream> using std::cin; using std::cout; user_input::user_input() { } void user_input::input_attempts() { int attempts; cout<<"Vvedite chislo popitok\n"; cin>>attempts; // emit attempt_set(attempts); } void user_input::new_attempt() { QChar attempt; QTextStream s(stdin); cout<<"Ugadayte bukvu"; attempt = s.readLine()[0]; emit attempt_stated(attempt); } void user_input::execute() { input_attempts(); } 
  • You seem to have a bug during the build. In addition, in the code I did not see the installation of the signal connection in the slot. Add to the question files h / cpp class game. Line 32 is especially interested in game.cpp. Kst, Qt instead of cout is usually qDebug is used - gil9red
  • @gil9red, I apologize, the error with the game class was fixed on its own and was not significant. (accidentally copied all the errors) D: \ code \ untitled18 \ user_input.cpp: 19: error:
  • one
    Add the Q_OBJECT line to the user_input class and reassemble - gil9red
  • @ gil9red, already tried. the following error pops up in addition to the already existing ones: D: \ code \ untitled18 \ user_input.cpp: 19: error: undefined
  • one
    @AndreyLobanovich, try this: object->show_tree(level + 1) . Regarding the undefined reference to vtable for user_input, the feeling that in the code in question this error should not occur. You need to update the code in question in accordance with the current code - gil9red

0