Qt desktop app
The casdoor-cpp-qt-example shows Casdoor sign-in in a Qt desktop app.
Run the example
前置要求
初始化
Set these 7 string parameters:
| 名称 | 描述 | 文件 |
|---|---|---|
| endpoint | 您的 Casdoor 服务器主机/域 | mainwindow.h |
| client_id | 您的 Casdoor 应用程序的客户端 ID | mainwindow.h |
| client_secret | 你的Casdoor应用的客户端密钥 | mainwindow.h |
| certificate | Casdoor 应用程序证书的公钥 | mainwindow.h |
| org_name | 您的Casdoor应用程序的名称 | mainwindow.h |
| app_name | 您的Casdoor应用程序的名称 | mainwindow.h |
| redirect_url | 您的Casdoor 应用程序的回调URL路径将是 casdoor://callback 如果没有提供 | mainwindow.h |
Default endpoint: http://localhost:8000 if not set.
Running
Qt Creator
- 打开
casdoor-cpp-qt-example.pro - 在
casdoor-cpp-qt-example.pro中设置OpenSSL的INCLUDEPATH - 按
Ctrl + R开始
效果预览

Click Sign In to open the login window. After sign-in, the user profile is shown.

Integration
Open the login window
// Load and display the login page of Casdoor
m_webview->page()->load(*m_signin_url);
m_webview->show();
Listen for the callback (TCP)
// 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();
close();
}
connect(m_tcpserver, SIGNAL(newConnection()), this, SLOT(on_tcp_connected()));
使用授权码获取用户信息
// 获取令牌并使用JWT库解析
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);