Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [main.cpp]
- #include "my_application.h"
- #include <thread>
- int main( int argc, char* argv[] )
- {
- printf( "QT_VERSION_STR: %s\n", QT_VERSION_STR );
- My_application app( argc, argv );
- QObject::connect( &app, &My_application::on_command, [&]( const char* buffer_ ) {
- printf("My_application::on_command: %s\n", buffer_);
- } );
- #if 0
- auto my_thread_proc = [&app](){
- for(int i = 0; i < 100; ++i)
- {
- app.post_command("some_command");
- }
- };
- auto my_thread1 = std::thread(my_thread_proc);
- #endif
- QWidget window;
- window.resize( 320, 240 );
- window.show();
- int result = app.exec();
- printf("---> after app.exec()\n");
- return result;
- }
- [my_application.h]
- #pragma once
- #include <QtWidgets>
- class My_application : public QApplication
- {
- Q_OBJECT
- public:
- explicit My_application( int& argc, char** argv );
- void post_command( const char* buffer_ );
- Q_SIGNAL void on_command( const char* buffer_ );
- };
- [my_application.cpp]
- #include "my_application.h"
- My_application::My_application( int& argc, char** argv ) : QApplication( argc, argv ){}
- void My_application::post_command( const char* buffer_ )
- {
- QMetaObject::invokeMethod(
- this, [this, buffer_] { Q_EMIT on_command( buffer_ ); }, Qt::QueuedConnection );
- }
- [CMakeLists.txt]
- cmake_minimum_required (VERSION 3.14)
- project(qt_tsan_tests)
- set(CMAKE_CXX_STANDARD 14)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- set(CMAKE_AUTOMOC ON)
- set(CMAKE_AUTORCC ON)
- add_executable (qt_tsan_tests my_application.h my_application.cpp main.cpp)
- find_package(Qt5 CONFIG COMPONENTS Widgets REQUIRED) # using Fedora36 default Qt 5.15.6
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer -Wall -Wextra -fsanitize=thread" )
- SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
- target_link_libraries(qt_tsan_tests PRIVATE Qt5::Widgets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement