QTextEdit没有显示在窗口上,也没有显示"hello“。不确定这里出了什么问题?
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QtGui/QTextEdit>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
QTextEdit *m_textint;
};
#endif // MAINWINDOW_H
-------------
#include "mainwindow.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.setGeometry(QRect(QPoint(100, 100),
QSize(400, 600)));
mainWindow.show();
return app.exec();
}
------------------
#include "mainwindow.h"
#include <QtCore/QCoreApplication>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_textint = new QTextEdit("hello");
m_textint->setGeometry(QRect(QPoint(10, 10),
QSize(50, 200)));
}发布于 2013-07-02 23:51:05
如果使用的是QtCreator,则可以将QTextEdit()对象附加到通常声明为centralWidget (QWidget)的对象。
我基本上是从自动生成的代码ui_mainwindow.h (使用QtCreator)中获取的。
void setupUi(QMainWindow *MainWindow)
{
QWidget* centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
QTextEdit* textEdit = new QTextEdit(centralWidget);
textEdit->setObjectName(QStringLiteral("textEdit"));
textEdit->append("Hello");
}https://stackoverflow.com/questions/17429955
复制相似问题