本主题与此相关:
Qt Creator 2.8.1 Qt 5.1.1 Qt Designer Linux Show a new Form
所以我创建了一些新对象:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
DialogPreviewHeader PreviewHeader;
Ui_DialogPreviewHeader UIDialog;
然后像这样使用它们:
void MainWindow::on_pushButtonPreviewHeader_clicked()
{
QString SendTxt = ui->lineEditClassName->text();
UIDialog.textBrowserPreviewHeaderFile->setPlainText(SendTxt);
PreviewHeader.show();
}
以前,显示表单有效,现在似乎使用UIDialog
. textBrowserPreviewHeaderFile
指针在类中设置,调试Ui_DialogPreviewHeader
时不为空。
另一个问题是学习如何将 mainWidget 和 Form 与 Slots 连接起来。
编辑:
当我这样做时:
void MainWindow::on_pushButtonPreviewHeader_clicked()
{
QString SendTxt = ui->lineEditClassName->text();
//UIDialog.textBrowserPreviewHeaderFile->setPlainText(SendTxt);
PreviewHeader.ui->textBrowserPreviewHeaderFile->setPlainText(SendTxt);
//PreviewHeader->ui->textBrowserPreviewHeaderFile->setPlainText(SendTxt);
//pushButtonPreviewHeader(SendTxt);
PreviewHeader->show();
}
各种组合无法编译:
-不是指针->
- 'Ui::DialogPreviewHeader* DialogPreviewHeader::ui' 是私有的PreviewHeader
.ui
使 PreviewHeader 成为指针并使用 -> 表单还表示 DialogPreviewHeader::ui' 是私有的。
我也尝试实现一个插槽,但从 MainWindow 到 DialogPreviewHeader 的另一种方式:
DialogPreviewHeader::DialogPreviewHeader(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogPreviewHeader)
{
ui->setupUi(this);
connect(
&MainWindow,
SIGNAL(pushButtonPreviewHeader(QString)),
this,
SLOT(ReceiveDataFromMainWidget(QString)));
}
但它不喜欢&MainWindow
.
无论如何 - 如果我发布所有代码会更好。我应该摆脱这个编辑并在这里发布,还是再做一个问题?
好的 - 这是所有代码 - 将来我会在开始时这样做!
#ifndef DIALOGPREVIEWHEADER_H
#define DIALOGPREVIEWHEADER_H
#include <QDialog>
namespace Ui {
class DialogPreviewHeader;
}
class DialogPreviewHeader : public QDialog
{
Q_OBJECT
public:
explicit DialogPreviewHeader(QWidget *parent = 0);
~DialogPreviewHeader();
private slots:
void on_buttonBox_accepted();
void ReceiveDataFromMainWidget(QString);
private:
Ui::DialogPreviewHeader *ui;
};
#endif // DIALOGPREVIEWHEADER_H
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "DialogPreviewHeader.h"
#include "ui_DialogPreviewHeader.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
//DialogPreviewHeader PreviewHeader;
//Ui_DialogPreviewHeader UIDialog;
private slots:
void on_pushButtonPreviewHeader_clicked();
void pushButtonPreviewHeader(QString);
void on_pushButtonPreviewImplFile_clicked();
void on_pushButtonWriteFiles_clicked();
void on_lineEditNSNames_textChanged(const QString &arg1);
void on_radioButtonNSIndividual_clicked();
void on_radioButtonOneNSAlias_clicked();
void on_lineEditClassName_textChanged(const QString &Text);
void on_lineEditClassNamePrepend_textEdited(const QString &arg1);
void on_pushButtonCancel_clicked();
void on_checkBoxPrependCharClassName_clicked();
private:
Ui::MainWindow *ui;
DialogPreviewHeader *PreviewHeader;
//Ui_DialogPreviewHeader.textBrowserPreviewHeaderFile *pHeader;
//textBrowserPreviewHeaderFile *pHeader;
};
#endif // MAINWINDOW_H
DialogPreviewHeader.h
#include "DialogPreviewHeader.h"
#include "ui_DialogPreviewHeader.h"
#include "MainWindow.h"
#include "ui_MainWindow.h"
DialogPreviewHeader::DialogPreviewHeader(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogPreviewHeader)
{
ui->setupUi(this);
connect(
Ui::MainWindow,
SIGNAL(pushButtonPreviewHeader(QString)),
this,
SLOT(ReceiveDataFromMainWidget(QString)));
}
DialogPreviewHeader::~DialogPreviewHeader()
{
delete ui;
}
void DialogPreviewHeader::on_buttonBox_accepted()
{
this->hide();
}
主文件
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
主窗口.cpp
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButtonPreviewHeader_clicked()
{
QString SendTxt = ui->lineEditClassName->text();
//UIDialog.textBrowserPreviewHeaderFile->setPlainText(SendTxt);
//PreviewHeader.ui->textBrowserPreviewHeaderFile->setPlainText(SendTxt);
//PreviewHeader->ui->textBrowserPreviewHeaderFile->setPlainText(SendTxt);
pushButtonPreviewHeader(SendTxt);
PreviewHeader->show();
}
void MainWindow::pushButtonPreviewHeader(QString) {
}
void MainWindow::on_pushButtonPreviewImplFile_clicked()
{
}
void MainWindow::on_pushButtonWriteFiles_clicked()
{
}
void MainWindow::on_lineEditNSNames_textChanged(const QString &arg1)
{
}
void MainWindow::on_radioButtonNSIndividual_clicked()
{
}
void MainWindow::on_radioButtonOneNSAlias_clicked()
{
}
void MainWindow::on_lineEditClassName_textChanged(const QString &Text)
{
}
void MainWindow::on_lineEditClassNamePrepend_textEdited(const QString &arg1)
{
}
void MainWindow::on_pushButtonCancel_clicked()
{
this->close();
}
void MainWindow::on_checkBoxPrependCharClassName_clicked()
{
}
您需要表格或 ui_ 标头吗?
编译器输出:
04:48:04: Running steps for project ClassWiz...
04:48:04: Configuration unchanged, skipping qmake step.
04:48:04: Starting: "/usr/bin/make"
g++ -c -pipe -std=c++11 -Wall -Wextra -pedantic -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5.1.1/5.1.1/gcc_64/mkspecs/linux-g++ -I../ClassWiz -I/opt/Qt5.1.1/5.1.1/gcc_64/include -I/opt/Qt5.1.1/5.1.1/gcc_64/include/QtWidgets -I/opt/Qt5.1.1/5.1.1/gcc_64/include/QtGui -I/opt/Qt5.1.1/5.1.1/gcc_64/include/QtCore -I. -I. -I. -o DialogPreviewHeader.o ../ClassWiz/DialogPreviewHeader.cpp
../ClassWiz/DialogPreviewHeader.cpp: In constructor 'DialogPreviewHeader::DialogPreviewHeader(QWidget*)':
../ClassWiz/DialogPreviewHeader.cpp:12:26: error: expected primary-expression before ',' token
make: *** [DialogPreviewHeader.o] Error 1
04:48:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project ClassWiz (kit: Desktop Qt 5.1.1 GCC 64bit)
When executing step 'Make'
04:48:05: Elapsed time: 00:01.