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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDateTime>
#define _USE_MATH_DEFINES
#include <math.h>
#include <QDebug>
#include <QRect>
#include <QRectF>
#include <QLine>
#include <QLineF>
#include <QPoint>
#include <QPointF>
#include <QSize>
#include <QSizeF>
#include <QThread>
#include <string>
#include <set>
#include <QLibrary>
#include <QLibraryInfo>
#include <QFileInfo>
#include <QSharedPointer>
#include <QDir>
#include <QStandardItemModel>
struct TestClass {
TestClass();
int m_i;
float m_f;
};
TestClass::TestClass() :
m_i(1),
m_f((float)M_E)
{
}
namespace Foo {
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass),
m_w(-42), m_wc("Hallo"), m_wqs("quallo"),
m_thread1(0),m_thread2(0),m_fastThread(0)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
terminateThread();
}
void MainWindow::simpleBP(int inc, const QString &inx)
{
int array[2] = {1,2};
m_w++;
QString x = QLatin1String("h\344all\366");
QString *xp = &x;
qDebug() << inc << inx << *xp;
Q_UNUSED(array)
}
void MainWindow::on_actionDialog_triggered()
{
complexBP(0, "ahh");
}
void MainWindow::complexBP(int *inc, QString inx)
{
m_w++;
const char *cc = "hallo";
const char *np = 0;
char c = 'c';
unsigned char uc = 'u';
short s = 5;
unsigned short us = 56;
int i = 5;
int *ip = &i;
const int * const ipc = &i;
unsigned int ui = 56;
long l = 5;
unsigned long ul = 55;
qint64 i64 = 54354;
quint64 iu64 = 54354;
float r = (float)M_PI;
double d = M_PI;
QString x = "Hallo ";
x += QDateTime::currentDateTime().toString();
const QString &xr = x;
std::string stdString = "SHallo";
std::list<std::string> stdList;
stdList.push_back(stdString);
std::list<int> intList;
intList.push_back(1);
intList.push_back(2);
TestClass tc;
++i;
qDebug() << i;
++i;
qDebug() << i;
QFileInfo dir(QDir::tempPath());
QDebug nsp = qDebug().nospace();
for (int j = 0; j < 80; j++) {
nsp << 'x';
}
QStringList sl;
sl << "one" << "two" << "three";
QList<int> qintList;
qintList << 4 << 6;
qDebug() << inc << inx << dir.absoluteFilePath();
//statusBar()->showMessage(x);
Q_UNUSED(cc)
Q_UNUSED(np)
Q_UNUSED(c)
Q_UNUSED(uc)
Q_UNUSED(s)
Q_UNUSED(us)
Q_UNUSED(ip)
Q_UNUSED(ipc)
Q_UNUSED(ui)
Q_UNUSED(l)
Q_UNUSED(ul)
Q_UNUSED(i64)
Q_UNUSED(iu64)
Q_UNUSED(r)
Q_UNUSED(d)
Q_UNUSED(xr)
}
void MainWindow::on_actionCrash_triggered()
{
QString h = "Hallo";
// fsdfd
QString *s = 0;
qDebug() << *s;
}
void MainWindow::on_actionSimpleBP_triggered()
{
simpleBP(42, "Hallo");
}
void MainWindow::on_actionIncr_watch_triggered()
{
m_w++;
}
class MyThread : public QThread {
public:
MyThread(int base, QObject *parent) : QThread(parent), m_base(base) {}
void run() override;
private:
int m_base;
};
void MyThread::run()
{
QString x;
const int end = m_base + 20;
for (int i = m_base; i < end; i++) {
qDebug() << "L" << currentThreadId() << i << '/' << end;
QThread::msleep(100);
if (i < 10) {
x += QString::number(i);
qDebug() << "lt 10";
x += ',';
}
}
qDebug() << "Terminating" << currentThreadId();
}
class MyFastThread : public QThread {
public:
MyFastThread(QObject *parent) : QThread(parent) {}
void run() override { qDebug() << "Done" << currentThreadId(); }
};
void MainWindow::terminateThread()
{
if (m_thread1 && m_thread1->isRunning())
m_thread1->terminate();
if (m_thread2 && m_thread2->isRunning())
m_thread2->terminate();
}
void MainWindow::on_actionThread_triggered()
{
if (!m_fastThread)
m_fastThread = new MyFastThread(this);
m_fastThread->start();
if (!m_thread1)
m_thread1 = new MyThread(0, this);
if (!m_thread1->isRunning())
m_thread1->start();
if (!m_thread2)
m_thread2 = new MyThread(20, this);
if (!m_thread2->isRunning())
m_thread2->start();
}
void MainWindow::on_actionException_triggered()
{
try {
throw (5) ;
} catch(int e) {
qDebug() << "caught "<< e;
}
}
void MainWindow::on_actionUncaughtException_triggered()
{
throw QString("eeh!") ;
}
void MainWindow::on_actionDumperBP_triggered()
{
m_w++;
std::string stdS;
std::list<int> sil;
QList<int> il;
std::list<std::string> stdStringList;
std::list<std::wstring> stdWStringList;
QStringList sl;
QString s = "hallo";
for (int c = 'a'; c < 'c'; c++) {
s += char(c + 23);
stdS += c;
sl.push_back(s);
stdStringList.push_back(std::string(1, c));
stdWStringList.push_back(std::wstring(1, c));
il.push_back(c);
sil.push_back(c);
qDebug() << s;
}
}
void MainWindow::on_actionExtTypes_triggered()
{
QVariant v1(QLatin1String("hallo"));
QVariant v2(QStringList(QLatin1String("hallo")));
QStringList vec;
vec.push_back("Hallo");
vec.push_back("Hallo2");
std::set<std::string> stdSet;
stdSet.insert("s1");
QWidget *ww = this;
QWidget &wwr = *ww;
QSharedPointer<QString> sps(new QString("hallo"));
QList<QSharedPointer<QString> > spsl;
spsl.push_back(sps);
QMap<QString,QString> stringmap;
QMap<int,int> intmap;
std::map<std::string, std::string> stdstringmap;
stdstringmap[std::string("A")] = std::string("B");
int hidden = 45;
if (1 == 1 ) {
int hidden = 7;
qDebug() << hidden;
}
QStandardItemModel *model =new QStandardItemModel;
model->appendRow(new QStandardItem("i1"));
QList <QList<int> > nestedIntList;
nestedIntList << QList<int>();
nestedIntList.front() << 1 << 2;
QVariantList vList;
vList.push_back(QVariant(42));
vList.push_back(QVariant("HALLO"));
stringmap.insert("A", "B");
intmap.insert(3,4);
QSet<QString> stringSet;
stringSet.insert("S1");
stringSet.insert("S2");
qDebug() << *(spsl.front()) << hidden;
Q_UNUSED(wwr)
}
void MainWindow::on_actionForeach_triggered()
{
QStringList sl {"1", "2", "3"};
for (const QString &s : std::as_const(sl))
qDebug() << s;
sl.clear();
qDebug() << sl;
}
void MainWindow::on_actionAssert_triggered()
{
Q_ASSERT(0);
}
}
void Foo::MainWindow::on_actionScopes_triggered()
{
int x = 0;
if (x == 0) {
int x = 1;
Q_UNUSED(x)
} else {
int x = 2;
Q_UNUSED(x)
}
qDebug() << x;
}
void Foo::MainWindow::on_actionLongString_triggered()
{
QString incr = QString::fromLatin1("0123456789").repeated(4);
QString s = incr;
for (int i = 0; i < 5; i++) {
s += incr;
qDebug() <<s;
}
}
void Foo::MainWindow::on_actionStdTypes_triggered()
{
std::string stdString = "s";
std::wstring stdWString = L"ws";
std::map<std::string, std::string> stdStringStringMap;
stdStringStringMap.insert(std::map<std::string, std::string>::value_type(stdString, stdString));
std::map<std::wstring, std::wstring> stdStringWStringMap;
stdStringWStringMap.insert(std::map<std::wstring, std::wstring>::value_type(stdWString, stdWString));
std::set<std::string> stringSet;
std::list<std::string> stringList;
std::vector<std::string> stringVector(1, "bla");
std::vector<std::wstring> wStringVector(1, L"bla");
}
void Foo::MainWindow::on_actionVariousQtTypes_triggered()
{
const QByteArray ba = "hallo\t";
QSize size = QSize(42, 43);
QSizeF sizeF(size);
QPoint p1 = QPoint(42, 43);
QPoint p2 = QPoint(100, 100);
QLine line(p1, p2);
QPointF p1f(p1);
QPointF p2f(p2);
QLineF linef(p1f, p2f);
QRect rect(p1, p2);
QRectF rectf(rect);
qDebug() << sizeF << linef << rectf;
}
|