logo
On this page

Example Source Code Running Guide

This article introduces how to quickly run through the example source code and experience the basic audio and video call service.

Prepare Environment

Please ensure that the development environment meets the following technical requirements:

  • Windows: Windows 7 or above, with Visual Studio 2019 or above installed.

  • macOS: macOS 11.0 or above, with Xcode 15.0 or above installed.

  • Linux: Any Linux distribution system with GLIBC 2.16 or above, supporting x86_64, aarch64, armhf architectures.

    Note
    • Linux RTC SDK only supports custom video rendering and does not support SDK automatic rendering (that is, the ZegoCanvas parameters for preview and playing stream are invalid). Therefore, in the example Demo, except for the custom video rendering topic, no images can be displayed.
    • You can refer to the Custom Video Rendering document and the example code in the "ZegoExpressExample/Examples/AdvancedVideoProcessing/CustomVideoRendering" directory of this Demo to implement rendering and displaying preview or playing stream images on Linux Qt.
  • Other general requirements:

    • CMake installed: Download CMake.
    • Qt installed (version 5.9 ~ 5.15): Download Qt. For developers using Qt for the first time, you can read its official tutorial to learn how to use it.
    • External devices such as microphones and cameras that support audio and video functions are working properly.
    Warning

    QtCreator versions prior to 8.0.1 may encounter issues where the Demo crashes because it cannot request camera and microphone permissions when debugging this Demo on macOS 12 Monterey or above. For details, refer to this issue.

    Solution: Download and install QtCreator 8.0.2 or above, and do not use the QtCreator that comes with the Qt5 installation package.

    Developers can download from QtCreator Github Release or Qt official website, or use HomeBrew to install: brew update && brew install --cask qt-creator

Prerequisites

A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained.

Warning

The SDK also supports Token authentication. If you need to upgrade the authentication method, please refer to How to upgrade from AppSign authentication to Token authentication.

After installing CMake and Qt, you need to add environment variables. The CMake and Qt paths provided below are for reference only. Users need to fill in according to the actual paths on their devices.

  • Windows system:

    1. Modify environment variables: Add C:\Program Files\CMake\bin to Path.
    2. Modify environment variables: Add C:\Qt\Qt5.12.12\5.12.12\msvc2017\bin to Path.
    3. Add user variable: Add QTDIR user variable as C:\Qt\Qt5.12.12\5.12.12\msvc2017
  • macOS system:

    export PATH="$PATH:$HOME/Qt5.12.12/5.12.12/clang_64/bin"
    export QTDIR="$HOME/Qt5.12.12/5.12.12/clang_64"
  • Linux system:

    export QTDIR="/usr/local/Qt-5.12.12"
    export PATH="$PATH:$QTDIR/bin"
    export LD_LIBRARY_PATH="$QTDIR/lib:$LD_LIBRARY_PATH"

Obtain Example Source Code

Note

This example source code is a desktop cross-platform Qt5 C++ application that supports both Windows/macOS/Linux platforms. The example source code comes with the latest version of SDK packages for all three platforms and can be run directly.

Example Source Code Directory Structure

The following structure is the file structure of the video subdirectory. All file paths involved below are relative to this directory.

.
├── README_zh.md
├── README.md
├── libs
│   ├── ScreenCapture
│   └── ZegoExpress
│       ├── linux # Directory for ZegoExpressVideo Linux SDK
│       ├── mac # Directory for ZegoExpressVideo macOS SDK
│       │   └── ZegoExpressEngine.xcframework
│       └── win # Directory for ZegoExpressVideo Windows SDK
│           ├── x64
│           └── x86
└── ZegoExpressExample
    ├── KeyCenter.cpp # Fill in the applied AppID and AppSign
    ├── KeyCenter.h
    ├── ZegoExpressExample.pro # Qt project file
    ├── Examples
    ├── HomePage
    ...

Run Example Source Code

  1. Modify the "/ZegoExpressExample/KeyCenter.cpp" file and fill in the "AppID" and "AppSign" required for SDK initialization.

    Warning

    Please use the AppID and AppSign obtained in Prerequisites of this article to fill in correctly, otherwise the example source code cannot run normally.

  2. Open the project.

    Use QtCreator to open the "./ZegoExpressExample/ZegoExpressExample.pro" project file.

  3. Compile and run the project.

    • Method 1: Run or Build directly through QtCreator.

      After opening the Qt project, click the "Run", "Debug", or "Build" buttons in the lower left corner to build and run the Demo.

    • Method 2: Build through qmake and make.

      • Windows

        1. Open cmd.exe and execute the cd \path\to\this\folder command to enter the directory where this file is located.
        2. Find the path to "vcvarsall.bat" (for example, VS 2019 version is in "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat").
        3. Execute the call "\path\to\your\vcvarsall.bat" x86 command to set the MSVC environment.
        4. Execute the qmake ZegoExpressExample\ZegoExpressExample.pro CONFIG+=Win32 -o .\build\Makefile command to generate Makefile through qmake.
        5. Execute the cd build command to enter the build directory, and build the project through the nmake command.
        6. Execute the cd .. command to return to the upper directory, and deploy the Qt App through the windeployqt .\bin\release\ZegoExpressExample.exe command.
      • macOS

        1. Open the terminal and execute the cd /path/to/this/folder command to enter the directory where this file is located.
        2. Execute the qmake ZegoExpressExample/ZegoExpressExample.pro CONFIG+=x86_64 -o ./build/Makefile command to generate Makefile through qmake.
        3. Execute the cd build command to enter the build directory, and build the project through the make command.
        4. Execute the cd .. command to return to the upper directory, and deploy the Qt App through the macdeployqt ./bin/release/ZegoExpressExample.app command.
      • Linux

        1. Open the terminal and enter the directory where the file is located cd /path/to/this/folder.
        2. Select compilation environment
          • Native compilation (supports x86_64, aarch64, armhf)
            1. Execute qmake ZegoExpressExample/ZegoExpressExample.pro -o ./build/Makefile to generate Makefile through qmake.
            2. Execute cd build to enter the build directory and execute make to build the project.
            3. In the bin/release directory of the upper directory, find the ZegoExpressExample project file, which can be run.
          • Cross compilation
            1. Currently supports cross-compiling for aarch64 or armhf target platforms in x86_64 environment (if you need to support other environments, please modify the configuration in ZegoExpressExample.pro yourself).
            2. Confirm that your machine has installed Qt everywhere for cross-compilation for the target platform. The following assumes cross-compilation for the aarch64 target platform and the corresponding Qt has been installed to the /usr/aarch64-linux-gnu/Qt-5.12.12 directory.
            3. Execute export TARGET_LINUX_ARCH=aarch64. This environment variable is to help ZegoExpressExample.pro identify the target platform to be built.
            4. Execute /usr/aarch64-linux-gnu/Qt-5.12.12/bin/qmake ZegoExpressExample/ZegoExpressExample.pro -o ./build/Makefile -spec linux-aarch64-gnu-g++ to generate Makefile for the aarch64 target platform through qmake.
            5. Execute cd build to enter the build directory and execute make to build the project.
            6. Copy the products in the bin/release directory and the /usr/aarch64-linux-gnu/Qt-5.12.12/lib directory to your target platform, and you can run it.

Experience Audio and Video Call/Live Streaming Functions

Run the project on the real device. After successful operation, you can see the local video screen.

For convenience, ZEGO provides a Web platform for debugging. On this page, enter the same AppID and RoomID, enter different UserIDs and corresponding Token, and you can join the same room to communicate with the real device. When the audio and video call starts successfully, you can hear the remote audio and see the remote video screen.

Previous

Common Error Codes

Next

Integrating SDK

On this page

Back to top