Skip to main content

Qt Desktop App

A Qt desktop app example for Casdoor.

How to run example


Qt6 sdk

OpenSSL toolkit


You need to initialize 7 parameters, which are all string type:

endpointYour Casdoor server host/domainmainwindow.h
client_idThe Client ID of your Casdoor applicationmainwindow.h
client_secretThe Client Secret of your Casdoor applicationmainwindow.h
certificateThe public key for the Casdoor application's certmainwindow.h
org_nameThe name of your Casdoor organizationmainwindow.h
app_nameThe name of your Casdoor applicationmainwindow.h
redirect_urlThe path of the callback URL for your Casdoor application, will be http://localhost:8080/callback if not providedmainwindow.h

If you don't set the parameter endpoint, this project will use the http://localhost:8000 as the defult Casdoor server.


Qt Creator

  1. Open
  2. Set the INCLUDEPATH of OpenSSL in
  3. Press Ctrl + R to start


After you run this Qt desktop application, a new window will be showed on your desktop. index

If you click Sign In botton, a login window will be showed on your desktop. login

After you login successfully, a user profile window will be showed on your desktop, it dispaly your user information. user profile

You can preview the whole process by the gif image below. preview gif

How to integrate

Open the login window

// Load and display the login page of Casdoor

Listen to the open application event

// Initialize the TcpServer object and listen on port 8080
m_tcpserver = new QTcpServer(this);
if(!m_tcpserver->listen(QHostAddress::LocalHost, 8080)) {
qDebug() << m_tcpserver->errorString();
connect(m_tcpserver, SIGNAL(newConnection()), this, SLOT(on_tcp_connected()));

Use auth code to get the user info

// Get token and parse it with the JWT library
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);