Skip to content

Instantly share code, notes, and snippets.

@polovik
polovik / qt_code_style.sh
Created August 26, 2016 12:02
Rreformatting C++ code according to Qt Coding Style
astyle --brackets=linux --indent=spaces=4 --indent-preprocessor --min-conditional-indent=0 --max-instatement-indent=40 --pad-oper --unpad-paren --pad-header --fill-empty-lines --align-pointer=name --align-reference=name --convert-tabs --lineend=linux --formatted `find ./ -type f -name '*.c' -or -name '*.h' -or -name '*.cpp'`
@polovik
polovik / qt_project.pro
Last active August 29, 2015 14:03
Add libraries from Qt framework to project's build folder - use "system" procedure for call "xcopy" on Windows for deployment.
TARGET = applicationName
DESTDIR = ../../build
outDir = $$DESTDIR
outDir = $$replace(outDir, /, \\)
system(mkdir $$outDir)
system(xcopy /V /R /Y "%QTDIR%\bin\libgcc_s_dw2-1.dll" $$outDir)
system(xcopy /V /R /Y "%QTDIR%\bin\libwinpthread-1.dll" $$outDir)
system(xcopy /V /R /Y "%QTDIR%\bin\libstdc++-6.dll" $$outDir)
system(xcopy /V /R /Y "%QTDIR%\bin\icu*.dll" $$outDir)
@polovik
polovik / unique_app_instance_WinApi.cpp
Last active August 29, 2015 13:59
Verify unique instance of application in WinApi (Visual Studio C++)
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
// Avoid multiple instances of application
const WCHAR *applicationMutexName = L"autorun_st";
HANDLE mutexAppHandle = CreateMutex(NULL, TRUE, applicationMutexName);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(mutexAppHandle);
return EXIT_FAILURE;
}
...
@polovik
polovik / unique_app_instance_Qt.cpp
Last active August 29, 2015 13:59
Verify unique instance of application in Qt
#include <QSharedMemory>
int main(int argc, char *argv[])
{
// Verify unique instance of application
QSharedMemory sharedMemory("service");
if (sharedMemory.attach())
return EXIT_FAILURE;
if (!sharedMemory.create(1))
return EXIT_FAILURE;
@polovik
polovik / logging_Qt.cpp
Last active July 20, 2023 11:52
Log to file or log to output panel in QtCreator for Qt
#include <QtDebug>
#include <QTranslator>
#include <QTextCodec>
#include <QLocale>
#include <QTime>
#include <QDir>
static QTextCodec *logCodec = NULL;
static FILE *logStream = NULL;
QString g_logFilePath = "";
@polovik
polovik / logging_Linux.c
Last active August 29, 2015 13:57
Log to file and log to syslog on Linux on C
#include <stdarg.h>
#include <syslog.h>
#include <time.h>
/**
* \brief Log levels. Used to control applications's verbosity.
*
* Verbosity is as follows: LOG_CRITICAL_ERROR is least verbose,
* LOG_EVENT is the most verbose log level.
*/
@polovik
polovik / logging_VisualStudio.cpp
Last active August 29, 2015 13:57
Log in file for Visual Studio
typedef enum {
LOG_INFO = 0, /**< Notification for better debugging */
LOG_WARNING = 1,/**< Incorrect work of application, but it doesn't lead to crash */
LOG_ERROR = 2 /**< Big problem - application is crashed */
} logLevel_e;
static FILE *g_logStream = NULL;
static WCHAR g_logFilePath[MAX_PATH];
static WCHAR g_logMessage[10000];