No appropriate default constructor available



  • Hello everybody, I'm trying to prove a program from a book for Threads test. I have not idea why the compiler show this error.
    The program, must show two buttons for start and stop two wires.

    Any help is appreciated greetings and thanks in advance
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /* main.cpp */
    //#include "mainwindow.h"
    #include <QApplication>
    #include "diaHilo.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
      //  MainWindow w;
     //   w.show();
        diaHilo h;
    
        return a.exec();
    }
    
    

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /* diaHilo.h */
    #include "hilo.h"
    
    class diaHilo : public QDialog{
        Q_OBJECT
    
    public:
        diaHilo::diaHilo(QWidget *parent);
        ~diaHilo();
    
    protected:
        void eCerrar(QCloseEvent *evento);
    
    private slots:
        void iniDet_hA();
        void iniDet_hB();
    private:
        hilo hA, hB;
        QPushButton *p_bhA, *p_bhB, *p_bQuitar;
    
    };
    
    
    #endif // diaHilo_H
    
    

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /*diaHilo.cpp*/
    #include "diaHilo.h"
    
    diaHilo::diaHilo(QWidget *parent) : QDialog(parent)
    {
        hA.ponMsg("A");
        hB.ponMsg("B");
        p_bhA = new QPushButton(tr("Iniciar A"));
        p_bhB = new QPushButton(tr("Iniciar B"));
        p_bQuitar = new QPushButton(tr("Quitar"));
        p_bQuitar->setDefault(true);
        connect(p_bhB, SIGNAL(clicked()),this,SLOT iniDet_hB());
        connect(p_bhA, SIGNAL(clicked()),this,SLOT iniDet_hB());
    
    }
    //*************************************************
    diaHilo::~diaHilo() //Destructor
    {
    
    }
    
    //*************************************************
    void diaHilo::iniDet_hA(){
        if(hA.isRunning()){
            hA.detener();
            p_bhA->setText(tr("Iniciar A"));
        }
            else{
                hA.start();
                p_bhA->setText(tr("Detener A"));
        }
    }
    //*************************************************
    void diaHilo::iniDet_hB(){
        if(hB.isRunning()){
            hB.detener();
            p_bhB->setText(tr("Iniciar B"));
        }
            else{
                hB.start();
                p_bhB->setText(tr("Detener B"));
        }
    }
    //*************************************************
    void eCerrar(QCloseEvent *evento){
        hA.detener();
        hB.detener();
        hA.wait();
        hB.Wait();
        evento->accept();
    }
    

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /*hilo.h*/
    #ifndef HILO_H
    #define HILO_H
    #include <QThread>
    
    class hilo : public QThread
    {
        Q_OBJECT
        volatile bool detenido;
    
        QString msgStr;
    
    public:
        hilo();
        ~hilo();
        void ponMsg(QString &msg);
        void detener();
    
    protected:
        void run();
    };
    
    #endif // HILO_H
    
    

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /*hilo.cpp*/
    #include "hilo.h"
    #include <iostream>
    
    
    using namespace std;
    hilo::hilo()
    {
        detenido = false;
    }
    //********************************************
    
    hilo::~hilo(){
    
    }
    //********************************************
    void hilo::run(){
      //  QString cadena = "prueba";
      // while (!detenido) cerr << qPrintable(mensajeStr);
        detenido = false;
        cerr << endl;
    }
    //*********************************************
    void hilo::detener(){
        detenido = true;
    }
    //*********************************************
    void hilo::ponMsg(QString &msg){
    
       // QString cadena = "prueba";
      //  qDebug() << msg << endl; //funciona igual incluyendo #include<QtDebug>
        cerr << qPrintable(msg);
    }
    //*********************************************
    
    

  • Qt Champions 2016

    hi
    diaHilo h;
    here u use default constructor
    but you only defined it with
    diaHilo::diaHilo(QWidget *parent);

    so
    diaHilo h(NULL);

    or with default value
    diaHilo::diaHilo(QWidget *parent=NULL);

    In non compiler language it says
    "Hey You create diaHilo with no parent/parameters and such constructor i dont have."



  • Thank you very much


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.