QT remote Linux file browser

Finished writing the windows local browser qt local file browser control_ shuxuekuanglihailong's column - CSDN blog_ qt file browser control has nothing to do. It writes a local file browser with qt. You can have a look. Main functions: 1. Tree navigation on the left. Double click or click to expand will automatically update the next level of data, and update the next level of directory on the premise of smooth operation. In the vernacular, it can click all the time without getting stuck, because it is dynamically loading data. 2. Automatic thread calculation of directory size, Entering at the beginning will show that the total size is being obtained. After calculation, update 3. The tree control on the left can be dragged left and right at will, or even dragged to the far left to hide directly. 4. The tree control on the left only displays the directory, and double clicking or clicking on the right side of the node will jump to the corresponding directory to play the role of navigation. Other functions 1. The table on the right distinguishes files and directories. 2. The control supports Chinesehttps://blog.csdn.net/shuxuekuanglihailong/article/details/113827529?spm=1001.2014.3001.5501

He began to think about how to access the server file system as easily as xftp, so after some coding, he encapsulated the following QT components:

xFileBrowserLinux inherits from QWidget. Of course, this is just entertainment. My ultimate goal is to write something more convenient than xftp. First encapsulate the linux side components:

The main principle is to use the encapsulated pssh client library to connect to the Linux server (using the user name and password), and then maintain a long connection to execute the command to obtain the file directory information and refresh the display

The main functions are as follows:

Automatic reconnection function  

After connecting to the Linux server, if the server hangs up or the sshd is out of service due to network reasons, it will be automatically reconnected until the reconnection succeeds and the information is obtained again. After disconnection, the status is displayed as a red dot and the connection is displayed as a green dot:

new file

Remote execution of touch

new directory

Execute mkdir -p remotely

ssh login

Call the local putty to bring in the server address, user name, password and port login. Even the password is automatically entered, pure and one click login. The effect is shown in the figure:

vnc login

Similar to ssh login, one click login to vnc uses the local vncviewer to call externally. Even the password is automatically entered, pure one click login  

rename

Execute mv command remotely

delete

Execute rm -rf command remotely

The main code of xFileBrowserLinux is as follows (poorly written, serious personal style, light spray):  

class xFileBrowserLinux : public QWidget
{
    Q_OBJECT

public:
    explicit xFileBrowserLinux(QWidget *parent = 0);
    pstring strhost;
    int iport;
    pstring strpwd;
    pstring struser;
    int iportvnc;
    pstring strpwdvnc;
    pstring getTypeNow();//Gets the current row type
    pstring getItemNow(pstring strcolname);
    pstring getPathFullNow();//Get the current full path (path plus file name)
    pstring getPathPwdNow();//Get current path
    QAction* pActionFirst;//The first menu is for adding after the outside
    QAction* newActionTop(QString name);//Add forward
    pssh *psh=NULL;
    ~xFileBrowserLinux();
    //It needs to be initialized by itself and will be reconnected automatically
    void init(pstring host="82.156.128.240",int port=22,pstring pwd="123.asdf",pstring user="root",int iportvnc=2,pstring pwdvnc="sjcs_325");
    void threadGetDataAndShow();
private:
    void ssh();
    void vnc();
private slots:
    void slotSetConnectState(bool bState);
    void slotDoubleClick(int row,int col);
    void on_pbutUpLevel_clicked();

    void on_pbutVNC_clicked();

    void on_pbutSSH_clicked();

signals:
    void sigShowTable(plist<pliststring> lmdata, int keyid=0);
    void sigDoubleClick(int row,int col);
    void sigSetConnectState(bool bState);
private:
    plist<pliststring> getNowFileAndDirs();

    bool bstop=false;
    Ui::xFileBrowserLinux *ui;
};

Of course, at present, this component can only look at information, and sftp transfer files and directories will be added later

Tags: C++ Linux Qt

Posted on Sat, 06 Nov 2021 15:18:32 -0400 by Tyree