QT common type conversion_qt uint_Fei classmates' blog-CSDN blog
qstring merge string in qt
https://www.yii666.com/blog/361427.html
QT formatting on QString (zero padding/hex conversion)_qstring formatting_Zhishou Blog-CSDN Blog
QString class—number_qstring::number_Acuity.'s Blog - CSDN Blog
LineEdit->setText() in qt outputs double - Developer Blog
https://tool.4xseo.com/a/56309.html
Qt: Convert QString to double type_qstring to double problem_xxgxgx's Blog-CSDN Blog
Method 1
Add a public pointer type static member variable of this class to the MainWindow class, and other files use this pointer to manipulate the controls in MainWindow.
Explanation:
The following shows how to create a listForm interface by pressing a button from mainWindow, and then control the edit box of the mainWindow window through an Insert and a Delete button on the listForm interface.
The mainWindow.h file is as follows:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <listform.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public:
static MainWindow *mutualUi;//!!!!!!!!!指针类型静态成员变量
void setLinetext(QString s);
private slots:
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
static MainWindow *mutualUi;//!!! Static member variables of pointer type
Why do you need to refer to this statically, detailed explanation of static in c++
The mainWindow.cpp file is as follows:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qdebug.h"
MainWindow *MainWindow::mutualUi = nullptr;//!!!!初始化,非常重要
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mutualUi = this;//!!!赋值,非常重要
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setLinetext(QString s)
{
ui->lineEdit->setText(s);
}
void MainWindow::on_pushButton_clicked()
{
listForm *l;
l = new listForm();
l->show();
}
MainWindow *MainWindow::mutualUi = nullptr;//! ! ! ! Initialization is very important
mutualUi = this;//! ! ! assignment, very important
listForm.cpp file
#include "listform.h"
#include "ui_listform.h"
#include "mainwindow.h"
listForm::listForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::listForm)
{
ui->setupUi(this);
}
listForm::~listForm()
{
delete ui;
}
void listForm::on_pushButton_clicked()
{
MainWindow::mutualUi->setLinetext("1111");//通过mainwindow的指针设置文本
}
void listForm::on_pushButton_2_clicked()
{
MainWindow::mutualUi->setLinetext("");//通过mainwindow的指针设置文本
}
MainWindow::mutualUi->setLinetext("1111");//Set the text
listForm.h file through the pointer of mainwindow:
#ifndef LISTFORM_H
#define LISTFORM_H
#include <QWidget>
namespace Ui {
class listForm;
}
class listForm : public QWidget
{
Q_OBJECT
public:
explicit listForm(QWidget *parent = 0);
~listForm();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::listForm *ui;
};
#endif // LISTFORM_H
Effect display:
run:
Create a listForm window:
Click Insert:
Click to delete: