Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No appropriate default constructor available
Qt 6.11 is out! See what's new in the release blog

No appropriate default constructor available

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • yczoY Offline
    yczoY Offline
    yczo
    wrote on last edited by yczo
    #1

    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);
    }
    //*********************************************
    
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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."

      1 Reply Last reply
      1
      • yczoY Offline
        yczoY Offline
        yczo
        wrote on last edited by
        #3

        Thank you very much

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved