本文介绍了为什么我的简单Qt代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想在Qt的主窗口中添加一个自定义类作为框架的子项:



customctrl.h :



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:

#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:

#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!!!

推荐答案

#include "customctrl.h"


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


customctrl::~customctrl() {;}



======== =================================


=========================================


customctrl *cc = new customctrl(ui->frame);
cc->show();


这篇关于为什么我的简单Qt代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:19