QT. How to inherit a class?

Hello!

There is a program that connects via bluetooth to the robot. I'm writing a gui to this program.
The problem is the following: in the file EpuckInterface.the hpp describes the interfaces to which you can connect:
#ifndef EPUCKINTERFACE_HPP__
#define EPUCKINTERFACE_HPP__

#include <string>
using std::string;

#include "EpuckTypes.hpp"

#include <meinheader.h>
#include <qdialog>
namespace gui {

class EpuckImage; // reference used in EpuckInterface

using gui::robots::epuck::IntFeld;
using gui::robots::epuck::led::LEDState;
class EpuckInterface
{
public:
 virtual ~EpuckInterface() { }
 virtual void reset() = 0;
 // drive
 virtual void setMotorSpeed( int left, int right ) = 0; //control wheels on the robot 
 virtual IntFeld<2> getMotorSpeed() = 0;
 virtual void setMotorPosition( int left, int right ) = 0;
 virtual IntFeld<2> getMotorPosition() = 0;
 virtual void stopRobot() = 0;

};
}
#endif</qdialog></meinheader.h></string>


I created MeinHeader.h :
#ifndef MEINHEADER_H
#define MEINHEADER_H
class MyWindow: public QDialog // Here I need,as I understand it, 
//add class EpuckInterface 
// if I did this: class MyWindow: public QDialog, public gui::EpuckInterface 
// the QT gives an error: error: expected class-name before '{' token
// if I'm trying to add gui::EpuckInterface 
//then: 'gui::EpuckInterface' has not been declared
// how do I include a class EpuckInterface that I could void TTEST(); to write 
// void TTEST(gui::EpuckInterface *e);? as MyWindow.cpp it requires to declare. 

{

{
Q_OBJECT
public:
 MyWindow(QWidget *parent = 0 );
private:
 EpuckInterface *e; // not working
 QPushButton *ttest; // for simplicity left one button 

private slots:

void TTEST(gui::EpuckInterface *e);

};
#endif // MEINHEADER_H


In the file MyWindow.cpp everything is standard:
#include <qobject>
#include <meinheader.h>
#include <epuckinterface.hpp>

MyWindow::MyWindow(QWidget *parent): QDialog(parent)
{

 e = new gui::EpuckInterface; // also not working
 ttest = new QPushButton(tr("ttest"));
connect(ttest,SIGNAL(clicked()),this,SLOT(TTEST(gui::EpuckInterface *e)));
 QGridLayout *grid = new QGridLayout;
 grid->addWidget(ttest,0, 5);
setLayout(grid);
StopClicked();
setWindowTitle("---");
}

void MyWindow::TTEST(gui::EpuckInterface *e)
{
 e->setMotorSpeed(100,50) ; // here I can not get MyWindow::MyWindow .....

}

}</epuckinterface.hpp></meinheader.h></qobject>


I hope my question is clear. Briefly, - how I can I set up slots to use
class EpuckInterface and all that is therein lies?
July 16th 19 at 00:43
1 answer
July 16th 19 at 00:45
You absolutely not work correctly with the UI in Qt. EpuckInterface looks like the class of logic and reason, you try to make him the ancestor of the UI class. Just create an instance of MyWindow EpuckInterface as a field.
Thanks for the reply. Possible example of how to do it? In the book max Chelles tokogo I have not found((( - richard.Stanton17 commented on July 16th 19 at 00:48
how to create a class field in C++? - Vicenta.Gleason88 commented on July 16th 19 at 00:51
: how to create it in QT given QT osobennoi. How to create a class field in C++ I understand, but how to do it in QT so it could be bolted to the slots no(( - richard.Stanton17 commented on July 16th 19 at 00:54
: there are no features of Qt, no specifics of working with namespaces, etc. Slots in fact — ordinary functions.

You need to create a simple C++ class that inherits from EpuckInterface with the implementation, to make it just C++ field MyWindow, MyWindow slots to invoke methods of the object heir EpuckInterface. - Vicenta.Gleason88 commented on July 16th 19 at 00:57
In fact of the matter is that no class I created does not inherit EpuckInterface. - richard.Stanton17 commented on July 16th 19 at 01:00
: well, create it! Simply C++ an heir completely without using Qt. - Vicenta.Gleason88 commented on July 16th 19 at 01:03
OK, then can you explain why in the same program file test.cpp

all that is in EpuckInterface works successfully?

include
using std::cout;
using std::endl;

int usage( char *progname )
{
cout << progname << "\n\n";
cout << "The robot''s number can be found on the package.\n";
cout << "Use 0 for a dummy interface.\n\n";
return 1;
}

//TODO: combine into one hpp
#include "EpuckInterface.hpp"
using gui::EpuckInterface;

#include "EpuckImage.hpp"
#include "EpuckTypes.hpp"
epuck namespace = gui::robots::epuck;

int epucktest( EpuckInterface *e )
{
namespace led = epuck::led;
using led::Toggle;
using led::Off;
using epuck::IntFeld;

cout << e->getVersion();

e->setBodyLED(Toggle);

cout << "Selector position is" << e->getSelectorPosition() << endl;

e->setMotorSpeed(100,-100);
IntFeld<2> speed = e->getMotorSpeed();
speed.print( "Speed:" );

IntFeld<3> accel = e->getAccelerometer();
accel.print( "Accel:" );

e->setFrontLED(Toggle);

cout << "Calibrating proximity sensors...";
cout.flush();
e->calibrateProximitySensors();

for (int i = 0; i < 8; i++)
e->setLED(i, Toggle);
cout << endl;

IntFeld<8> prox = e->getProximitySensors();
prox.print( "Proximity sensor:" );

IntFeld<8> light = e->getLightSensors();
light.print( "Light sensor:" );

e->setMotorPosition(1000,100);
IntFeld<2> pos = e->getMotorPosition();
pos.print( "Motor position:" );

e->stopRobot();

cout << e->cameraMode();
cout << "Requesting camera image...";
gui::image EpuckImage = e->cameraShot();
cout << "done." << endl;
image.hexdump();

e->playSound(3);
IntFeld<3> micro = e->getMicrophones();
micro.print( "Microphone levels:" );
e->playSound(0);

cout << e->getHelpText();

e->setFrontLED(Off);
e->setBodyLED(Off);

return 0;
}

//TODO: make c++
#include // atoi
#include // strcmp

#include "if_block.hpp" // real epuck, blocking io
#include "if_nonblock.hpp" // real epuck, nonblocking io
#include "EpuckDummy.hpp" // for dummy epuck simulation

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main( int argc, char **argv )
{
using gui::robots::epuck::EpuckID;
using gui::robots::epuck::Epuck;
using gui::EpuckDummy;

QApplication app(argc, argv);
MyWindow *widget = new MyWindow(0);
widget->show();

int argca=2386;
EpuckID id = argca;
EpuckInterface *epuck;
if ( id )
epuck = new Epuck( id );
try
{

epucktest( epuck );

}
catch( std::runtime_error e )
{
delete epuck;
throw e;
}
delete epuck;
return app.exec();
//return 0;
}
Written an hour ago - richard.Stanton17 commented on July 16th 19 at 01:06

Find more questions by tags QtC++