I am trying to use qt with adtf 3.3 .
From the documentation of adtf (https://support.digitalwerk.net/adtf/v3/adtf_html/page_external_dependencies.html) and example from adtf using qt(https://support.digitalwerk.net/adtf/v3/adtf_html/page_demo_qt_video_display_code.html).
Brief intro about what i am trying to do.
I have created one ui file using QtDesigner and then i generated manually header file using uic compiler then also generated moc file since i have signal and slots functionality i also need moc file to call metaobjects.
So Now i would like to do is instead of generating manually header file using uic and moc file i wanted to generate moc file during build time using
set(CMAKE_AUTOMOC_ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
the reason why i am doing like this if i change some functionality or added some signal and slots then i need to generate separatley and add in the sources file.
So basically my header file generated by uic contains info about objects used in qt form. Basically it translates xml file type which contains information about ui to header file using uic compiler.
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QWidget>
#include <QLineEdit>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
QGroupBox *groupBox_dummy;
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
//Form->resize(960, 480);
Form->setFixedSize(960, 480);
/*Contains several qobjects removed intentionally as it makes post so long*/
retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE
and then i have a moc file generated my moc compiler they are always generated for all QObject classes. They are absolutely required for meta stuff to work, so things like: signals for example.
My CMAKELists look like
set (CMAKE_CXX_STANDARD 11)
include(FetchContent)
find_package(ADTF REQUIRED HINTS ${ADTF_DIR} COMPONENTS filtersdk ui)
adtf_use_qt(Widgets)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
find_package(Eigen3 CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/eigen/share/eigen3/cmake)
set(OpenCV_STATIC ON)
find_package(OpenCV CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/opencv)
# include directories
include_directories(inc)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${EIGEN3_INCLUDE_DIR})
# specify target
set(TARGET_NAME dummy)
set (TARGET_SOURCES
inc/uic_dummy.h->file generated by uic compiler. this code snipper is shown above
inc/dummy.h -> this basically contains several methods like createview and severalt hings and also slots (for qt functionality)
inc/stdafx.h -> contains all includes in this file
src/dummy.cpp->definitions of all the functions mentioned in dummy.h
src/moc_dummy.cpp-> moc file everytime i need to keep in the sources list. However i want to generate it in build time instead of saying like this uisng CMAKE_AUTOMOC ON
)
adtf_add_filter(${TARGET_NAME} ${TARGET_SOURCES})
target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Widgets ${OpenCV_LIBS} adtf::ui)
adtf_disable_qt_warnings(${TARGET_NAME})
adtf_install_target(${TARGET_NAME} ${CMAKE_INSTALL_PREFIX}/dummy/dummy)
adtf_create_plugindescription(
/*removed intentionall as it is not the area of the concern in this scenario*/
)
So my question is can i generate moc file in build time?
Since I am using adtf_use_qt(widgets) and in cmake gui i point out qt_dir then everything works fine. However i need to keep moc file in the sources.
Normally when i use qt withouf adtf i basicall use find_package(qt) and also use
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE AUTORCC ON)
Then i will only keep my ui file in the sources and then it generates
everyhting forme. Ideally i would like to know if i can do the same for adtf.
Please excuse me if my question is not clear.If you need any more info please ask i will try to elaborate in a much better way than this. Thanks
are you still having trouble creating your moc files?
Maybe you only have to add your xxx.ui file to the filter sources.
The ui_xxx.h could be included within your source files.
For example:
set(PLUGIN_TARGETNAME your_filter)
adtf_add_filter(${PLUGIN_TARGETNAME}
${PLUGIN_TARGETNAME}.h
${PLUGIN_TARGETNAME}.cpp
${PLUGIN_TARGETNAME}.ui
)
target_link_libraries(${PLUGIN_TARGETNAME} PRIVATE
adtf::systemsdk
adtf::filtersdk
adtf::ui)
set_target_properties(${PLUGIN_TARGETNAME} PROPERTIES FOLDER src)
adtf_create_plugindescription(
TARGET ${PLUGIN_TARGETNAME}
PLUGIN_SUBDIR "bin")
set_target_properties(${PLUGIN_TARGETNAME}
PROPERTIES AUTOMOC ON AUTOUIC ON AUTOGEN_TARGET_DEPENDS ${PLUGIN_TARGETNAME}.ui)
Related
I am using scons to build my project. Now I got a problem.
I use
env.StaticLibrary('a', [a1.o, a2.o])
to get a static library "liba.a".
Now I pass "liba.a" to another part of my project, in the part, I will generate another static library named "libb.a", and this will merge "liba.a" with some other object files.
The code like this:
env.StaticLibrary('b', ['liba.a', 'b1.o', 'b2.o'] )
In this question
Linking static libraries, that share another static library we know that we can not simply merge a static library into another static library, Because this may result in some symbol problems.
Now I want to solve this problem in this way:
First get the object file of 'liba.a'. Then merge this object files with new object files to generate the final 'libb.a'.
But I found I can not find a method or function to get the object files in a static library with scons.
Can anyone help me ?
Sounds like you just want to use the same object files for 2 different libraries.
You could do something like this:
env = Environment()
env.StaticLibrary('a', ['a1.o', 'a2.o'])
env.StaticLibrary('b', ['b1.o', 'b2.o', 'a1.o', 'a2.o'])
Additionally, instead of dealing with the Object files, you could directly specify the source files. In this case, SCons will only compile the source files once, as needed.
env.StaticLibrary('a', ['a1.c', 'a2.c'])
env.StaticLibrary('b', ['b1.c', 'b2.c', 'a1.c', 'a2.c'])
Also, remember that each SCons builder returns a list of targets (each being a SCons Node). The list may have one or several entries. So, for example, the following target variable will contain the library target, and all of the objects built:
target = env.StaticLibrary('a', ['a1.c', 'a2.c'])
for t in target: print str(t)
I am exporting a global variable from a dll using __declspec(dllexport) and importing the same in the client exe using __declspec(dllimport).
The global variable in the dll is being updated with time in a separate thread. I want to receive this updated data in my client .exe, but I am not getting it. What I get is the only initial value of the global variable every time I read the data using a timer in the client exe.
What is the explanation of such a behavior? and what can I do to achieve what I want to achieve? Is there an option without including get() and set() exported functions from the dll?
Here is the code that is exported from dll:
typedef struct{
int iTotalQueues;
int iCurrentQueue;
wchar_t szQueueName[100];
}UPDATE_STATUS_DATA;
__declspec(dllexport) UPDATE_STATUS_DATA UpdateStatusData;
This structure members are updated in a loop for a long time. The updating code is in the dll itself.
Here is the code that is imported in the exe:
typedef struct{
int iTotalQueues;
int iCurrentQueue;
wchar_t szQueueName[100];
}UPDATE_STATUS_DATA;
__declspec(dllimport) UPDATE_STATUS_DATA UpdateStatusData;
I am reading this data inside a timer response and not getting the updated values.
The code in your question as you would expect when built into a simple test project. So, here are the two explanations that I can concoct:
You are taking a copy of UpdateStatusData in your executable. And so the changes to the value of UpdateStatusData made in the DLL do not get reflected in the copy.
Your DLL is, for some reason, not modifying the struct.
I have slight problem or misunderstanding with hiding symbols in xcode 4.6. I have searched everywhere in the web and cant find any posts having the same issue.
Currently I have created a framework project with a simple header file containing so:
class Test
{
public:
Test(){}
Test(){}
};
int a(int n) {return n;}
__attribute__((visibility("hidden"))) int b(int n) {return n;}
__attribute__((visibility("default"))) int c(int n) {return n;}
class X
{
public:
virtual ~X();
};
class __attribute__((visibility("hidden"))) Y
{
public:
virtual ~Y();
};
class __attribute__((visibility("default"))) Z
{
public:
virtual ~Z();
};
X::~X() { }
Y::~Y() { }
Z::~Z() { }
In the project settings i have made sure that "Symbols hidden by default" is switched to YES and therefore only the functions int c and the class z will be exported or visible to other projects.
I build the framework with no errors or warnings and then copy/add it to a cocoa application for testing.
I am able to include the header file but I am still able to access all classes and functions.
I hope someone can explain why or where i am going wrong or have encountered this problem before?
regards
Your problem is, you are declaring everything in the header file. That means even if the symbols are not exported, when you import the header file into another file, these symbols are re-created in the project where you imported the header and thus they are of course available within this project.
I'm trying to explain this to you by a simpler sample. Assume you have two files, MyLib.h and MyLib.c.
MyLib.h:
int add(int a, int b);
MyLib.c:
int add(int a, int b) { return a + b };
If you now give add a hidden visibility and compile everything to a library (MyLib), the library will have no symbol for add (as it is hidden). As a result, if you include MyLib.h into another file, make a call to the add function there and finally link this file against MyLib, you will get a linker error, since the linker will complain that it cannot find an implementation for add (it only has a declaration from the H file).
However, if you pack the function into the header itself, so MyLib.h is:
int add(int a, int b) { return a + b };
and you give add a hidden visibility, the library will also have no symbol for add, but when you include the header into another file, this header will create a symbol for add in exactly the file that imported it and thus of course you will not get a linker error and be able to call add.
Importing a H file just means copying the whole content of the H file to the location where the import instruction has been found. Now think about it: If you copy the whole content of the H file in your question to the top of the file where you are including it, of course all symbols declared there are visible and usable in the current project. Why wouldn't they be visible or useable? They are not in the library, yes, but they are in the header and thus do get compiled when your other project is compiled.
Symbols that are supposed to not be visible outside your current project ("hidden" symbols) should never appear in any public header file of your framework. Why would you announce the existence of symbols in a header files that cannot be used anyway? Actually, in most cases not exposing the symbols in the header file is already enough to prevent people from using them. The reason for not exporting them either is only that if a symbol exists, it can be used, even if it is not exposed by any header file (therefor you just need to write your own header file or declaring it as external symbol directly in your code). So making symbols hidden is just a safeguard to make sure that it cannot be used under any circumstances.
I have a number of test classes in C# (NUnit Test scripts, compiling on Mono).
Instead of compiling all unit tests into one big assembly, as usual, I'd like to compile the individual class files into separate assemblies. To do so, I'd like to do a dependency analysis, so I can generate the separate assemblies automatically.
What I'm looking for is similar to class dependency analyser which exists for Java
Have a look at Mono Cecil.
This library has the capability to 'reflect' (not a very good name for it) on the actual assembly image to do analysis. This assumes that you would be willing to compile down to a 'big' assembly in order to run the dependency analysis using Mono.Cecil.
Edit In fact, you might simply use Cecil to copy the 'big' assembly while filtering out parts of it. That way, you'll not have much of the complexity of compiling the separate assemblies; Look at CecilRoundtrip sample for an example of how to roundtrip (read -> manipulate -> save) assemblies in Cecil.
I have previously published quite extensive examples of how to use Mono Cecil for 'advanced' searches (static call tree search, in essence):
Get types used inside a C# method body
Look if a method is called inside a method using reflection
The absolute bare minimum that would be most useful to you would probably be:
var types = assemblies
.SelectMany(assembly => assembly.MainModule.Types.Cast<TypeDefinition>());
var dependencies = types.ToDictionary(
key => key,
typedef => new HashSet<string>(typedef.Methods.Cast<MethodDefinition>()
.Where(method => null != method.Body) // ignore abstracts and generics
.SelectMany(method => method.Body.Instructions.Cast<Instruction>())
.Select(instr => instr.Operand)
.OfType<TypeReference>().Distinct()
// .Where(type => !type.Namespace.StartsWith("System"))
.Select(type => type.Name)));
foreach (var entry in dependencies)
{
Console.WriteLine("{0}\t{1}", entry.Key.Name, string.Join(", ", entry.Value.ToArray()));
}
Note the commented line optionally filters out things from the framework (System.String, System.Char etc.).
This will list required types per declared type. To list types used, simply tag on the lookup to assembly name:
.Select(type => type.Module.Assembly.Name.Name)));
Sample output of the first kind (types required):
SegmentSoortKenmerk SegmentSoortKenmerk
OperatorValue
Koppelpad Koppelpad, CodeLeidendVolgend
RedenWaarschuwing
RelExceptions
GecontroleerdDocument GecontroleerdDocument, GecontroleerdDocument[]
OwiExtraKenmerk OwiExtraKenmerk, Gegeven, BackofficeRelatie
Entiteit Entiteit, SleutelSysteemObject[], EniteitType
Similar query but using the assembly name lookup:
SegmentSoortKenmerk Lspo.Business
OperatorValue
Koppelpad Lspo.Business
RedenWaarschuwing
RelExceptions
GecontroleerdDocument Lspo.Business
OwiExtraKenmerk Lspo.Business
Entiteit Lspo.Business
Assuming you want to run nunit tests on mono, that should work just fine, ( I am happily using NUnit 2.5 and 2.4 on mono 2.10.6 ).
One common mistake is only copying or keeping track of the .dll file containing the tests. Like any program, the test has dependencies, in your case, they will at least be nunit.framework.dll plus the class/assembly you wish to test ( and any of it's dependencies )
If all you want however is to find the assemblies a given dll references (things it needs to run) you can do this quite easily:
using System.Reflection;
void PrintRefs( string dllfile ){
var asm = Assembly.ReflectionOnlyLoad ( dllfile );
foreach ( var aname in asm.GetReferencedAssemblies() ){
Console.WriteLine( aname.Name );
}
}
Beware, this will only find the names of assemblies the program or library was compiled with, not any that it might dynamically load at runtime.
I'm trying to implement http://msdn.microsoft.com/en-us/library/dd377634%28v=VS.85%29.aspx on Qt, to generate a poster frame/thumbnail for video files.
I have installed both Windows Vista and Windows 7 SDK. I put:
#include "qedit.h"
in my code (noting there is also one in C:\Qt\2010.04\mingw\include), I add:
win32:INCLUDEPATH += $$quote(C:/WindowsSDK/v6.0/Include)
to my *.pro file. I compile and get " error: sal.h: No such file or directory". Finding this in VC++ I add
win32:INCLUDEPATH += $$quote(C:/Program Files/Microsoft Visual Studio 10.0/VC/include)
And now have 1400 compile errors. So, I abandon that and just add:
win32:LIBS += C:/WindowsSDK/v7.1/Lib/strmiids.lib
to my *.pro file and try to run (without including any headers):
IMediaDet mediadet;
But then I get "error: IMediaDet: No such file or directory".
#include "qedit.h"
gives me the same error (it looks like it's pointing to the Qt version) and
#include "C:/WindowsSDK/v6.0/Include/qedit.h"
goes back to generating 1000's of compile errors.
Sigh, so much trouble for what should be 10 lines of code...
Thanks for your comments and help
Since you say you are "a C++/Qt newbie" then I suspect that the real issue may be that you are attempting to load the library yourself rather than simply linking your application to it?
To link an external library into your application with Qt all you need to do is modify the appropriate .pro file. For example if the library is called libfoo.dll you just add
LIBS += -L/path/to/lib -lfoo
You can find more information about this in the relevant section of the qmake manual. Note that qmake commonly employs Unix-like notation and transparently does the right thing on Windows.
Having done this you can include the library's headers and use whatever classes and functions it provides. Note that you can also modify the project file to append an include path to help pick up the headers eg.
INCLUDEPATH += /path/to/headers
Again, more information in the relevant section of the qmake manual.
Note that both these project variables work with relative paths and will happily work with .. to mean "go up a directory" on all platforms.
Note that qedit.h requires dxtrans.h, which is part of DirectX9 SDK.
You can find dxtrans.h in DirectX SDK from August 2006. Note that dxtrans.h is removed from newer DirectX SDKs.
Do you have access to the source of the external library? The following assumes that you do.
What I do when I need to extract a class from a library with only functions resolved, is to use a factory function in the library.
// Library.h
class SomeClass {
public:
SomeClass(std::string name);
// ... class declaration goes here
};
In the cpp file, I use a proxy function outside the extern "C" when my constructor requires C++ parameters (e.g. types such as std::string), which I pass as a pointer to prevent the compiler from messing up the signature between C and C++. You can avoid the extra step if your constructor doesn't require parameters, and call new SomeClass() directly from the exported function.
// Library.cpp
#include "Library.h"
SomeClass::SomeClass(std::string name)
{
// implementation details
}
// Proxy function to handle C++ types
SomeClass *ImplCreateClass(std::string* name) { return new SomeClass(*name); }
extern "C"
{
// Notice the pass-by-pointer for C++ types
SomeClass *CreateClass(std::string* name) { return ImplCreateClass(name); }
}
Then, in the application that uses the library :
// Application.cpp
#include "Library.h"
typedef SomeClass* (*FactoryFunction)(std::string*);
// ...
QLibrary library(QString("MyLibrary"));
FactoryFunction factory = reinterpret_cast(library.resolve("CreateClass"));
std::string name("foobar");
SomeClass *myInstance = factory(&name);
You now hold an instance of the class declared in the library.