-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
85 lines (73 loc) · 2.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "mainwindow.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QStringListModel>
#include <QListView>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QPushButton>
#include <QObject>
#include <QLabel>
#include <QStringList>
#include <QHBoxLayout>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
#include <QJsonDocument>
#include <QDebug>
#include <QJsonArray>
#include <QUrl>
#include <QApplication>
#include "httprequest.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/res/openai_logo.svg"));
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "chatgpt_" + QLocale(locale).name();
if (translator.load(":/res/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
#if 1
MainWindow w;
w.show();
#else
// Create the main window
QWidget window;
window.setWindowTitle("Chat Window");
// Create the message list view
QListView messageListView;
QStringListModel messageListModel;
QStringList slis{"John: Hello", "Jane: Hi there"};
messageListModel.setStringList(slis);
messageListView.setModel(&messageListModel);
// Create the message input box and send button
QTextEdit messageInputBox;
QPushButton sendButton("Send");
QObject::connect(&sendButton, &QPushButton::clicked, [&]{
int row = messageListView.currentIndex().row();
messageListModel.insertRow(row);
messageListModel.setData(messageListModel.index(row),
messageInputBox.toPlainText());
messageInputBox.clear();
});
// Create the layout
QVBoxLayout mainLayout;
mainLayout.addWidget(&messageListView);
QHBoxLayout inputLayout;
inputLayout.addWidget(&messageInputBox);
inputLayout.addWidget(&sendButton);
mainLayout.addLayout(&inputLayout);
// Set the layout to the main window
window.setLayout(&mainLayout);
// Show the window
window.show();
#endif
return a.exec();
}