-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple Qt example #9
Open
aurelienrb
wants to merge
1
commit into
master
Choose a base branch
from
8-create-simple-demo-application-in-qt-t
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": 2, | ||
"configurePresets": [ | ||
{ | ||
"name": "base-preset", | ||
"hidden": true, | ||
"binaryDir": "${sourceDir}/build/${presetName}", | ||
"generator": "Ninja", | ||
"cacheVariables": { | ||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/${presetName}/install" | ||
} | ||
}, | ||
{ | ||
"name": "debug", | ||
"inherits": "base-preset", | ||
"cacheVariables": { | ||
"CMAKE_BUILD_TYPE": "Debug" | ||
} | ||
}, | ||
{ | ||
"name": "release", | ||
"inherits": "base-preset", | ||
"cacheVariables": { | ||
"CMAKE_BUILD_TYPE": "Release" | ||
} | ||
}, | ||
{ | ||
"name": "visual-studio", | ||
"inherits": "base-preset", | ||
"generator": "Visual Studio 16 2019", | ||
"cacheVariables": { | ||
"CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo" | ||
} | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "release", | ||
"configurePreset": "release" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
rm -rf build/release | ||
mkdir -p build/release | ||
cd build/release | ||
cmake -G Ninja ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install | ||
ninja | ||
#/bin/bash | ||
set -eu | ||
|
||
rm -rf build/release | ||
cmake --preset="release" | ||
cmake --build --preset="release" | ||
cmake --build --preset="release" --target install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@echo off | ||
REM script to be used on Windows to generate and open a VC++ solution | ||
|
||
REM where to put the build files | ||
set BUILDDIR=%~dp0build | ||
|
||
REM the VC++ solution file | ||
set SLNFILE=%BUILDDIR%\visual-studio\DebugVision.sln | ||
|
||
REM make Qt visible | ||
set QTDIR=C:\Qt\6.2.2\msvc2019_64 | ||
if not exist %QTDIR% (echo invalid Qt bin path: "%QTDIR%" && GOTO:FAILURE) | ||
set PATH=%QTDIR%\bin;%PATH% | ||
|
||
REM find VC++ | ||
set "VCPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" | ||
if not exist "%VCPATH%" ( | ||
set "VCPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" | ||
) | ||
|
||
REM generate build files if not already done | ||
if not exist %SLNFILE% ( | ||
REM make VC++ & cmake visible | ||
REM make sure to install "C++ CMake tools for Windows" in VS installer | ||
call "%VCPATH%\VC\Auxiliary\Build\vcvars64.bat" || GOTO:FAILURE | ||
|
||
if exist %BUILDDIR% rmdir /s/q %BUILDDIR% | ||
mkdir %BUILDDIR% || GOTO:FAILURE | ||
compact /c /q %BUILDDIR% > nul | ||
cmake --preset="visual-studio" || GOTO:FAILURE | ||
) | ||
|
||
REM open the VC++ solution | ||
start %SLNFILE% | ||
|
||
REM success! | ||
GOTO:EOF | ||
|
||
:FAILURE | ||
echo Failure! | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
# script to install a recent cmake version in CI build env | ||
|
||
set -eu | ||
|
||
CMAKEVER=3.22.1 | ||
curl -sL https://github.com/Kitware/CMake/releases/download/v${CMAKEVER}/cmake-${CMAKEVER}-linux-x86_64.tar.gz -o cmake.tar.gz | ||
tar xzf cmake.tar.gz | ||
ls -l | ||
mv cmake-${CMAKEVER}-linux-x86_64 /opt/cmake | ||
ln -s /opt/cmake/bin/cmake /usr/bin/cmake | ||
ln -s /opt/cmake/bin/ctest /usr/bin/ctest | ||
ln -s /opt/cmake/bin/cpack /usr/bin/cpack | ||
rm cmake.tar.gz | ||
|
||
cmake -version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(debug.vision.application) | ||
add_subdirectory(qt.demoapp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include "AsyncFileScanner.h" | ||
|
||
#include <QDirIterator> | ||
#include <QtConcurrent> | ||
|
||
AsyncFileScanner::AsyncFileScanner() | ||
{ | ||
qDebug() << __func__; | ||
connect(&m_futureWatcher, &QFutureWatcher<void>::started, this, &AsyncFileScanner::scanStarted); | ||
connect(&m_futureWatcher, &QFutureWatcher<void>::finished, this, &AsyncFileScanner::scanFinished); | ||
} | ||
|
||
AsyncFileScanner::~AsyncFileScanner() | ||
{ | ||
qDebug() << __func__; | ||
stop(); | ||
} | ||
|
||
void AsyncFileScanner::startFolderScan(const QString& rootDir) | ||
{ | ||
qDebug() << __func__; | ||
if (isScanInProgress()) | ||
{ | ||
qWarning() << "can't start a new file scanning: another scan is already in progress"; | ||
return; | ||
} | ||
|
||
m_future = QtConcurrent::run([this, rootDir] { | ||
qDebug() << "async file scanner started"; | ||
const QStringList files = performFileSearchStage(rootDir, {"*.log", "log*.txt"}); | ||
if (!m_future.isCanceled()) | ||
{ | ||
performFileReadStage(files); | ||
} | ||
qDebug() << "async file scanner ended"; | ||
}); | ||
m_futureWatcher.setFuture(m_future); | ||
} | ||
|
||
void AsyncFileScanner::stop() | ||
{ | ||
qDebug() << __func__; | ||
if (m_future.isRunning()) | ||
{ | ||
qDebug() << "stopping async file scanner..."; | ||
m_future.cancel(); | ||
m_future.waitForFinished(); | ||
} | ||
} | ||
|
||
QStringList AsyncFileScanner::performFileSearchStage(const QString& rootDir, const QStringList& patterns) | ||
{ | ||
Q_ASSERT(m_future.isRunning()); // we expect to run as an async task | ||
|
||
qDebug() << "searching for files of kind" << patterns; | ||
QStringList result; | ||
result.reserve(1'000); | ||
|
||
QDirIterator it(rootDir, patterns, QDir::Files, QDirIterator::Subdirectories); | ||
while (it.hasNext()) | ||
{ | ||
if (m_future.isCanceled()) | ||
{ | ||
qDebug() << "file search was canceled"; | ||
break; | ||
} | ||
|
||
QString filePath = it.next(); | ||
result += filePath; | ||
emit foundNewFile(rootDir, filePath); | ||
} | ||
|
||
qDebug() << "end of file search, number of file found:" << result.size(); | ||
return result; | ||
} | ||
|
||
static int countTextLinesInFile(const QString& filePath) | ||
{ | ||
QFile file{filePath}; | ||
if (!file.open(QIODevice::ReadOnly)) | ||
{ | ||
qCritical() << "failed to read file" << filePath; | ||
return 0; | ||
} | ||
|
||
QTextStream stream(&file); | ||
const QString text = stream.readAll(); | ||
return text.isEmpty() ? 0 : 1 + text.count(QLatin1Char('\n')); | ||
} | ||
|
||
void AsyncFileScanner::performFileReadStage(const QStringList& files) | ||
{ | ||
qDebug() << "starting to read file content"; | ||
for (const QString& filePath : files) | ||
{ | ||
if (m_future.isCanceled()) | ||
{ | ||
qDebug() << "reading file content was canceled"; | ||
break; | ||
} | ||
|
||
emit countedFileLineNumbers(filePath, countTextLinesInFile(filePath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
// Type used to scan folders for log files via a background task | ||
class AsyncFileScanner : public QObject | ||
{ | ||
Q_OBJECT | ||
signals: | ||
void scanStarted(); | ||
void scanFinished(); | ||
void foundNewFile(QString rootDir, QString filePath); | ||
void countedFileLineNumbers(QString filePath, int lineCount); | ||
|
||
public: | ||
AsyncFileScanner(); | ||
~AsyncFileScanner(); | ||
|
||
[[nodiscard]] bool isScanInProgress() const | ||
{ | ||
return m_future.isRunning(); | ||
} | ||
|
||
void startFolderScan(const QString& rootDir); | ||
|
||
void stop(); | ||
|
||
private: | ||
QStringList performFileSearchStage(const QString& rootDir, const QStringList& patterns); | ||
void performFileReadStage(const QStringList& files); | ||
|
||
private: | ||
bool m_isScanning = false; | ||
QFuture<void> m_future; | ||
QFutureWatcher<void> m_futureWatcher; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
add_executable(qt.demoapp | ||
AsyncFileScanner.cpp | ||
AsyncFileScanner.h | ||
main.cpp | ||
MainWindow.cpp | ||
MainWindow.h | ||
WidgetFileTextViewer.cpp | ||
WidgetFileTextViewer.h | ||
WidgetFileTreeView.cpp | ||
WidgetFileTreeView.h | ||
# special files | ||
pch.h | ||
images/images.qrc | ||
) | ||
target_precompile_headers(qt.demoapp PRIVATE pch.h) | ||
target_link_libraries(qt.demoapp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent) | ||
set_target_properties(qt.demoapp PROPERTIES AUTOMOC ON AUTORCC ON) | ||
|
||
if (WIN32) | ||
# display the Win32 console only for debug builds | ||
set_target_properties(qt.demoapp PROPERTIES WIN32_EXECUTABLE $<IF:$<CONFIG:Debug>,FALSE,TRUE>) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake 3.20 required for the presets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is aligned and serve as a example towards showing up a time-series of events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meged it in my fork mm-s/DebugVision.git