Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Okay, so I'm trying to simply add a custom class of mine as a child of a frame in my main window in Qt:

customctrl.h:

C++
#ifndef CUSTOMCTRL_H
#define CUSTOMCTRL_H

#include <QWidget>

namespace Ui {
class customctrl;
}

class customctrl : public QWidget
{
    Q_OBJECT
    
public:
    explicit customctrl(QWidget *parent = 0);
    ~customctrl();
    
private:
    Ui::customctrl *ui;
};

#endif // CUSTOMCTRL_H


and my main window:

C++
#include "customctrl.h"

//A bunch of code...
{
    customctrl *cc = new customctrl();
    ui->frame->layout()->addWidget(cc);
}


And yet, every time I run this code, my program crashes and I don't know why. Is there something I'm missing? What am I doing wrong? Please help me! Thank you!!!
Posted
Comments
Richard MacCutchan 21-Jun-13 3:34am    
Step through the code with the debugger to see exactly what is happening.
RadXPictures 24-Jun-13 15:18pm    
When I try debugging I get a "debugger not set up" error. Any idea?

You need to implement all methods from 'customctrl.h' file in 'customctrl.cpp' file:

customctrl.cpp
========================================
#include "customctrl.h"


customctrl::customctrl(QWidget *parent = 0) : QWidget(parent) 
{
  resize(50, 50);
  setWindowTitle("Qt");
}


customctrl::~customctrl() {;}

=========================================
 
Share this answer
 
v2
Comments
RadXPictures 23-Jun-13 22:28pm    
Sorry, probably should have posted it, but I already had:

#include "customctrl.h"
#include "ui_customctrl.h"

customctrl::customctrl(QWidget *parent) :
QWidget(parent),
ui(new Ui::customctrl)
{
ui->setupUi(this);
}

customctrl::~customctrl()
{
delete ui;
}

It was auto-generated.
Wow... just figured out an unbelievably simple solution. Thanks anyways guys.

C++
customctrl *cc = new customctrl(ui->frame);
cc->show();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900