Compile QHexView into a static library with cmake

I. Introduction

This article mainly briefly describes how to use cmake to compile the open source QHexView into a static library. The author defaults that the reader has downloaded and successfully installed cmake, and has downloaded the QHexView source code. The author provides readers with cmake and QHexView download links as follows.
cmake downloads the official website
github QHexView source code.
The author has made QHexView compatible with qt5.6.3. The
author recommends compiling with the processed QHexView, otherwise the compiled result may be slightly different from that of the author.

Two, cmake compilation

1. Create a build folder

Create a build folder in QHexView for the purpose of saving the files generated by cmake compilation

Please add a picture description

2. Load the directory

  • Load the QHexView source directory (Browse Source)
  • Load and compile the generated folder directory (the build directory we created in step1, Browse Build)
  • Configure
  • Select to generate the project, such as: Here I choose to compile and generate Visual Studio 12 2013 project
  • Select the generation platform, you can choose arm, win32, x64. For example: here I choose to compile and generate win32
  • Keep the default and click Finish

Please add a picture description

3. Load Qt5_DIR

  • The red area shows Qt5_DIR-NOTFIND
  • Click ok in the pop-up window
  • Click on the red area to display Qt5_DIR-NOTFIND, three dots will appear, click to enter. Then find the Qt5 folder in D:\Qt\Qt5.6.3\5.6.3\msvc2013\lib\cmake\Qt5, select the Qt5 folder, the D drive here can be other drives, please install Qt according to you path to choose

Please add a picture description
Please add a picture description

4. Configuration and generation

  • Click Configure
  • Click Generate to
    appear
    Configuring done
    Generating done

Please add a picture description
Please add a picture description

5. View the build directory

At this point we can see that in the build directory, cmake has generated the file shown in the figure, we can use vs2013 to open the solution QHexView.sln

Please add a picture description

6. compile

Generate > Generate Solution, as shown in the figure, the qhexview.lib file has been generated in the ...\QHexView\build\Debug folder

Please add a picture description

7. View static library files

At this point, the static library is compiled

Please add a picture description

3. Instructions for use

1. Add library

Right click on the project file > Add Library

Please add a picture description

2. External library

Select external library

Please add a picture description

3. Load the library

3.1 Select library file

Select the qhexview.lib file under ...\QHexView\build\Debug

Please add a picture description

3.2 Select the include path

  • Select the include path: ...\QHexView
  • select windows
  • Select static library
  • Remove all ticked options in the red box

Please add a picture description

4. finish

Please add a picture description

5.qmake

Build and click to execute qmake

Please add a picture description

4. Example code

1. Header file

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include <QGridLayout>
#include <QPushButton>

#include "QHexView/qhexview.h"


namespace Ui {
    
    
class MainWindow;
}

class MainWindow : public QMainWindow
{
    
    
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:


private:
    Ui::MainWindow *ui;
    QHexView *m_hexView;
};

#endif // MAINWINDOW_H

2. Source files

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

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    
    
    ui->setupUi(this);
    m_hexView = new QHexView(true,this);
    setCentralWidget (m_hexView);

    QByteArray data("123456");
    m_hexView->setShowData (data);

}

MainWindow::~MainWindow()
{
    
    
    delete ui;
}

5. Demonstration effect

Please add a picture description

Guess you like

Origin blog.csdn.net/qq_42815643/article/details/129279619