Commit f91b71a786c5adc6dd424ad96c38d9518cc31f33
- Diff rendering mode:
- inline
- side by side
tests/CMakeLists.txt
(2 / 0)
|   | |||
| 37 | 37 | # benchmarks | |
| 38 | 38 | testfilters | |
| 39 | 39 | ) | |
| 40 | |||
| 41 | add_subdirectory(pluginpointertest) |
|   | |||
| 1 | cmake_minimum_required(VERSION 2.6) | ||
| 2 | project(sometest) | ||
| 3 | |||
| 4 | find_package(Qt4 REQUIRED) | ||
| 5 | include(${QT_USE_FILE}) | ||
| 6 | |||
| 7 | include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOOURCE_DIR}/grantlee_core ) | ||
| 8 | |||
| 9 | set(myplugin_headers myobject.h) | ||
| 10 | set(myplugin_sources myobject.cpp) | ||
| 11 | |||
| 12 | qt4_wrap_cpp(_plugin_moc_srcs ${myplugin_headers}) | ||
| 13 | |||
| 14 | add_library(myplugin SHARED ${myplugin_sources} ${_plugin_moc_srcs}) | ||
| 15 | set_target_properties(myplugin | ||
| 16 | PROPERTIES PREFIX "" | ||
| 17 | ) | ||
| 18 | target_link_libraries(myplugin | ||
| 19 | ${QT_QTCORE_LIBRARIES} | ||
| 20 | ) | ||
| 21 | |||
| 22 | add_executable(main_app main.cpp ${myplugin_sources} ${_plugin_moc_srcs}) | ||
| 23 | target_link_libraries(main_app | ||
| 24 | ${QT_QTCORE_LIBRARIES} | ||
| 25 | ) |
tests/pluginpointertest/main.cpp
(58 / 0)
|   | |||
| 1 | /* | ||
| 2 | This file is part of the Grantlee template system. | ||
| 3 | |||
| 4 | Copyright (c) 2010 Stephen Kelly <steveire@gmail.com> | ||
| 5 | |||
| 6 | This library is free software; you can redistribute it and/or | ||
| 7 | modify it under the terms of the GNU Lesser General Public | ||
| 8 | License as published by the Free Software Foundation; either version | ||
| 9 | 2 of the Licence, or (at your option) any later version. | ||
| 10 | |||
| 11 | This library is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | Library General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU Lesser General Public | ||
| 17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | */ | ||
| 20 | |||
| 21 | #include <QtCore> | ||
| 22 | #include <QObject> | ||
| 23 | |||
| 24 | #include "myinterface.h" | ||
| 25 | #include "myobject.h" | ||
| 26 | #include "pluginpointer_p.h" | ||
| 27 | |||
| 28 | using Grantlee::PluginPointer; | ||
| 29 | |||
| 30 | // #define DONT_LEAK | ||
| 31 | |||
| 32 | int main(int argc, char **argv) | ||
| 33 | { | ||
| 34 | QCoreApplication app(argc, argv); | ||
| 35 | |||
| 36 | #ifndef DONT_LEAK | ||
| 37 | QPluginLoader loader( app.applicationDirPath() + "/myplugin.so" ); | ||
| 38 | QObject *raw_plugin = loader.instance(); | ||
| 39 | MyInterface *if1 = qobject_cast<MyInterface*>(raw_plugin); | ||
| 40 | |||
| 41 | qDebug() << if1->double_it( 5 ); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | PluginPointer<MyInterface> p1( app.applicationDirPath() + "/myplugin.so" ); | ||
| 45 | PluginPointer<MyInterface> p2; | ||
| 46 | |||
| 47 | if (true) | ||
| 48 | { | ||
| 49 | PluginPointer<MyInterface> p3( app.applicationDirPath() + "/myplugin.so" ); | ||
| 50 | p1 = p3; | ||
| 51 | PluginPointer<MyInterface> p4( p3 ); | ||
| 52 | PluginPointer<MyInterface> p5 = p3; | ||
| 53 | } | ||
| 54 | |||
| 55 | qDebug() << p2->double_it( 15 ); | ||
| 56 | |||
| 57 | app.exit(); | ||
| 58 | } |
|   | |||
| 1 | |||
| 2 | #ifndef MYINTERFACE_H | ||
| 3 | #define MYINTERFACE_H | ||
| 4 | |||
| 5 | class MyInterface | ||
| 6 | { | ||
| 7 | public: | ||
| 8 | virtual ~MyInterface() {} | ||
| 9 | |||
| 10 | virtual int double_it( int input ) = 0; | ||
| 11 | }; | ||
| 12 | |||
| 13 | Q_DECLARE_INTERFACE( MyInterface, "org.example.MyInterface/1.0" ) | ||
| 14 | |||
| 15 | #endif |
|   | |||
| 1 | |||
| 2 | #include "myobject.h" | ||
| 3 | |||
| 4 | #include <QtPlugin> | ||
| 5 | |||
| 6 | |||
| 7 | MyObject::MyObject(int stop, QObject *parent) | ||
| 8 | : QObject(parent) | ||
| 9 | { | ||
| 10 | m_data.fill('o', 2000000); | ||
| 11 | |||
| 12 | if (stop > 0) | ||
| 13 | MyObject *o = new MyObject(--stop, this); | ||
| 14 | } | ||
| 15 | |||
| 16 | int MyObject::double_it( int input ) | ||
| 17 | { | ||
| 18 | return input * 2; | ||
| 19 | } | ||
| 20 | |||
| 21 | Q_EXPORT_PLUGIN2( myplugin, MyObject ) |
|   | |||
| 1 | |||
| 2 | #ifndef MYOBJECT_H | ||
| 3 | #define MYOBJECT_H | ||
| 4 | |||
| 5 | #include <QObject> | ||
| 6 | #include "myinterface.h" | ||
| 7 | |||
| 8 | class MyObject : public QObject, public MyInterface | ||
| 9 | { | ||
| 10 | Q_OBJECT | ||
| 11 | Q_INTERFACES( MyInterface ) | ||
| 12 | public: | ||
| 13 | MyObject( int stop = 4, QObject *parent = 0 ); | ||
| 14 | |||
| 15 | int double_it( int input ); | ||
| 16 | |||
| 17 | private: | ||
| 18 | QByteArray m_data; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #endif |

