Qt development from opening to entry

First of all, there was a problem of " Cannot find file ....... pro." . It was found that there were Chinese characters in the path, so it was cut to another directory.

New problems emerged when building after the cut:

:: warning: Qmake does not support build directories below the source direct

After searching, it is found that it is the problem of the pro.user file, and the directory path of the original compilation will be saved in this file, so after cutting it, you need to delete this file and then compile. Then successfully pop up the exe interface:

qt interface part can refer to the video

Gangster Videos

When popping the window through the QMessageBox :: information function, it is found that the Chinese characters are garbled, as shown in the figure

Later added in main.cpp

//在头文件添加
#include<QTextCodec>

//在main()中添加
QTextCodec::setCodecForLocale(QTextCodec::codecForName("gb2312"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("gb2312"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb2312"));

Solve the problem of garbled Chinese characters (QT 4 version).

Qt connects to the database, this time using the sqllite database, failed to start using mysql, the problem has not been solved, sqllite is easier to use, reference

Use of sqlite database in ot development

 

A new window pops up:

//比如弹出一个登录窗口,在上述步骤建立了login.h、login.cpp、login.ui

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "login.h"

void MainWindow::on_action_login_triggered()
{
    login *w = new login();
    w->show();
}

Get the content of the input box and output it through debug:

    //需要include <QDebug>

    QString username = ui->UsernameEdit->text();
    qDebug()<<"username is "<<username;
    QString password = ui->PasswordEdit->text();
    qDebug()<<"password is "<<password;

Clear the contents of the input box and close the window:

ui->lineEdit->clear();
this->close();

Data transmission between different windows: (using slot functions and signals, I have read some articles before and feel that I have written too much, but it is quite simple)



在窗口一的.h文件中定义接收函数

void receiveData(QString data);

在窗口二的.h文件中定义发送信号

signals:
    void sendData(QString data);

在窗口一跳转到窗口二函数中进行连接
void MainWindow::on_action_login_triggered()
{
    login *w = new login();
    connect(w,SIGNAL(sendData(QString)),this,SLOT(receiveData(QString)));//信号连接
    w->show();
}

在窗口一的.cpp文件中写接收函数
void MainWindow::receiveData(QString data)
{
    user = data;
}

在窗口二的.cpp文件中发送信号
  emit sendData(username);
就可以了

widget settings:

ui->tableWidget->show();
    ui->tableWidget->setRowCount(20);
    ui->tableWidget->verticalHeader()->setVisible(false);//隐藏水平header
    ui->tableWidget->setColumnWidth(0,50);
    ui->tableWidget->setColumnWidth(1,70);
    ui->tableWidget->setColumnWidth(2,70);
    ui->tableWidget->setColumnWidth(3,200);
    ui->tableWidget->setColumnWidth(4,80);
    ui->tableWidget->setColumnWidth(5,190);
    ui->tableWidget->setColumnWidth(6,70);
    ui->tableWidget->setColumnWidth(7,70);
    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

 

 

 

 

 

Published 125 original articles · Like 31 · Visits 60,000+

Guess you like

Origin blog.csdn.net/Fiverya/article/details/97628858