C++ 如何创建QWidget
我正在尝试创建一个C++ 如何创建QWidget,c++,qt,qwidget,C++,Qt,Qwidget,我正在尝试创建一个QWidget,但我一直收到错误: /media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:53: error: no matching function for call to ‘QWidget::setLayout(QScrollArea*&)’ mainWin -> setLayout(scrollArea);
QWidget
,但我一直收到错误:
/media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:53: error: no matching function for call to ‘QWidget::setLayout(QScrollArea*&)’
mainWin -> setLayout(scrollArea);
^
main window.cpp
#include "mainwindow.h"
#include <QScrollArea>
#include <QApplication>
MainWindow::MainWindow() :
scrollArea(new QScrollArea)
{
mainWin = new QWidget();
// Create the button, make "this" the parent
m_button = new QPushButton("My Button", this);
// set size and location of the button
m_button->setGeometry(QRect(QPoint(100, 100), QSize(200, 50)));
// Connect button signal to appropriate slot
connect(m_button, SIGNAL (released()), this, SLOT (handleButton()));
label = new QLabel(QApplication::translate("windowlayout", "Name:"));
lineEdit = new QLineEdit();
layout = new QHBoxLayout();
layout->addWidget(label);
layout->addWidget(lineEdit);
scrollArea->setLayout(layout);
mainWin -> setLayout(scrollArea);
}
#包括“mainwindow.h”
#包括
#包括
MainWindow::MainWindow():
滚动区域(新QScrollArea)
{
mainWin=新的QWidget();
//创建按钮,使“this”成为父级
m_按钮=新的QPushButton(“我的按钮”,此按钮);
//设置按钮的大小和位置
m_按钮->设置几何体(QRect(QPoint(100100),QSize(20050));
//将按钮信号连接到适当的插槽
连接(m_按钮,信号(释放()),此,插槽(把手按钮());
标签=新的QLabel(QApplication::translate(“windowlayout”,“Name:”);
lineEdit=新的QLineEdit();
布局=新的QHBoxLayout();
布局->添加小部件(标签);
布局->添加小部件(lineEdit);
滚动区域->设置布局(布局);
mainWin->setLayout(滚动区域);
}
main window.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
class QActionGroup;
class QScrollArea;
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow();
private:
QWidget *mainWin;
QScrollArea *scrollArea;
QStringList pluginFileNames;
QPushButton *m_button;
QLabel *label;
QLineEdit *lineEdit;
QHBoxLayout *layout;
QVBoxLayout *vBox;
};
#endif
\ifndef主窗口
#定义主窗口
#包括
#包括
#包括
#包括
类QActionGroup;
QScrollara类;
类主窗口:公共QWidget
{
Q_对象
公众:
主窗口();
私人:
QWidget*mainWin;
QScrollArea*滚动区域;
QStringList PluginlineNames;
QPushButton*m_按钮;
QLabel*标签;
QLineEdit*lineEdit;
QHBoxLayout*布局;
QVBoxLayout*vBox;
};
#恩迪夫
以下是我如何尝试将所有事情联系在一起:
#include "mainwindow.h"
#include <QtPlugin>
#include <QApplication>
#include <QDesktopWidget>
Q_IMPORT_PLUGIN(BasicToolsPlugin)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow window;
QDesktopWidget dw;
int x=dw.width()*0.7;
int y=dw.height()*0.7;
window.setFixedSize(x,y);
window.show();
return app.exec();
}
#包括“mainwindow.h”
#包括
#包括
#包括
Q_导入_插件(BasicToolsPlugin)
int main(int argc,char*argv[])
{
QApplication应用程序(argc、argv);
主窗口;
qdesktopdw;
int x=dw.width()*0.7;
int y=dw.height()*0.7;
窗口。设置固定大小(x,y);
window.show();
返回app.exec();
}
我做错了什么?我是一个QT/C++新手,如果问题太明显了,
先谢谢你。首先,我什么地方都看不见
new QScrollearea()
第二,这:
QScrollArea*&
尤其是
*&
大多数情况下是指针/引用不匹配的提示请阅读手册。警告说明了一切:qwidget没有将布局设置为滚动区域的方法。
setLayout
请求QLayout
指针,您给它一个qscrollara
指针。编译器不喜欢这样。-1对不起,这个问题与您的问题完全不匹配,而且很难通过将windows的布局设置为。。。滚动区域。请将其压缩到MCVE,缩小问题范围,阅读文档等。