Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created September 8, 2017 08:49
Show Gist options
  • Save 0xlitf/a983959341595cbcd608fd71de342efa to your computer and use it in GitHub Desktop.
Save 0xlitf/a983959341595cbcd608fd71de342efa to your computer and use it in GitHub Desktop.
qt file
QString LoginWrapper::getToken() {
qDebug() << "m_tokenFilename: " << m_tokenFilename;
QFile file(m_tokenFilename);
if (!file.exists()) {
file.open( QIODevice::ReadWrite | QIODevice::Text );
file.close();
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return "";
}
QTextStream in(&file);
auto all = in.readAll();
qDebug() << "all: " << all;
return all;
}
void LoginWrapper::clearToken() {
QFile file(m_tokenFilename);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
return;
}
file.resize(0);
}
void LoginWrapper::saveToken(const QString& token) {
QFile file(m_tokenFilename);
if(!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
return;
}
QTextStream in(&file);
in << token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment