Results 1 to 3 of 3

Thread: Help with qt plugin

  1. #1
    Join Date
    Apr 2013
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Help with qt plugin

    Hi,

    I'm implementing teh tutorial qt-project.org/doc/qt-5.0/qtdoc/gettingstartedqml.html I have implemented correctly everything about QML and GUI works ok. At the moment of using the plugin I'm able to generate both libFileDIalog.a and FileDialog.dll.

    However when i integrate the plugin into the qml text editor things doesn't compile as it is supposed to do. This is my .pro file

    Qt Code:
    1. # Add more folders to ship with the application, here
    2. folder_01.source = qml/TextEditor
    3. folder_01.target = qml
    4. DEPLOYMENTFOLDERS = folder_01
    5.  
    6. # Additional import path used to resolve QML modules in Creator's code model
    7. QML_IMPORT_PATH =
    8.  
    9. symbian:TARGET.UID3 = 0xE6CF9A7F
    10.  
    11. # Smart Installer package's UID
    12. # This UID is from the protected range and therefore the package will
    13. # fail to install if self-signed. By default qmake uses the unprotected
    14. # range value if unprotected UID is defined for the application and
    15. # 0x2002CCCF value if protected UID is given to the application
    16. #symbian:DEPLOYMENT.installer_header = 0x2002CCCF
    17.  
    18. # Allow network access on Symbian
    19. symbian:TARGET.CAPABILITY += NetworkServices
    20.  
    21. # If your application uses the Qt Mobility libraries, uncomment the following
    22. # lines and add the respective components to the MOBILITY variable.
    23. # CONFIG += mobility
    24. # MOBILITY +=
    25.  
    26. # Speed up launching on MeeGo/Harmattan when using applauncherd daemon
    27. # CONFIG += qdeclarative-boostable
    28.  
    29. # Add dependency to Symbian components
    30. # CONFIG += qt-components
    31.  
    32. # The .cpp file which was generated for your project. Feel free to hack it.
    33. SOURCES += main.cpp
    34.  
    35. INCLUDEPATH += "D:/DSUsers/uidv3469/Tutoriales/Qt/QML/TextEditor/qml/TextEditor/Library"
    36. LIBS += "D:/DSUsers/uidv3469/Tutoriales/Qt/QML/TextEditor/qml/TextEditor/Library/FileDialog.dll"
    37. HEADERS += "D:/DSUsers/uidv3469/Tutoriales/Qt/QML/TextEditor/qml/TextEditor/Library/dialogPlugin.h" \
    38. "D:/DSUsers/uidv3469/Tutoriales/Qt/QML/TextEditor/qml/TextEditor/Library/directory.h" \
    39. "D:/DSUsers/uidv3469/Tutoriales/Qt/QML/TextEditor/qml/TextEditor/Library/file.h"
    40.  
    41. # Please do not modify the following two lines. Required for deployment.
    42. include(qmlapplicationviewer/qmlapplicationviewer.pri)
    43. qtcAddDeployment()
    To copy to clipboard, switch view to plain text mode 

    it marks me this errors:

    Qt Code:
    1. debug/moc_dialogPlugin.o:moc_dialogPlugin.cpp:(.rdata$_ZTV12DialogPlugin[vtable for DialogPlugin]+0x38): undefined reference to `DialogPlugin::registerTypes(char const*)'
    2. debug/moc_dialogPlugin.o:moc_dialogPlugin.cpp:(.rdata$_ZTV12DialogPlugin[vtable for DialogPlugin]+0x50): undefined reference to `non-virtual thunk to DialogPlugin::registerTypes(char const*)'
    3. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:74: undefined reference to `Directory::saveFile()'
    4. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:75: undefined reference to `Directory::loadFile()'
    5. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:122: undefined reference to `Directory::filesCount() const'
    6. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:123: undefined reference to `Directory::files()'
    7. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:124: undefined reference to `Directory::filename() const'
    8. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:125: undefined reference to `Directory::fileContent() const'
    9. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:131: undefined reference to `Directory::setFilename(QString const&)'
    10. debug/moc_directory.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_directory.cpp:132: undefined reference to `Directory::setFileContent(QString const&)'
    11. debug/moc_file.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_file.cpp:102: undefined reference to `File::name() const'
    12. debug/moc_file.o:D:\DSUsers\uidv3469\Tutoriales\Qt\QML\TextEditor-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/moc_file.cpp:108: undefined reference to `File::setName(QString const&)'
    13. collect2: ld returned 1 exit status
    14. mingw32-make.exe[1]: *** [debug/TextEditor.exe] Error 1
    15. mingw32-make.exe: *** [debug] Error 2
    16. 18:25:11: The process "D:\TOOL\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    17. Error while building project TextEditor (target: Desktop)
    18. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    I looked at the libraries generated qith a text editor, and apparently the references to the methods are inside the library so I would say the reference exist, but for some reason it is no being find.

    Could anybody shed some light on why this thing is not finding the reference to mentioned functions?


    Best regards,

    Ulises Vega

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with qt plugin

    Is this .pro file for the plugin or for the application? What is the "Directory" class? Where is it defined? If it is defined in a plugin then you can't access it directly from the application. If you want to access it from the application, you need to link your application against the library (which stops being a plugin at this moment). If you do that, remember to export all the symbols from the library that you want to be accessible in code using that library.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2013
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Help with qt plugin

    Quote Originally Posted by wysota View Post
    Is this .pro file for the plugin or for the application? What is the "Directory" class? Where is it defined? If it is defined in a plugin then you can't access it directly from the application. If you want to access it from the application, you need to link your application against the library (which stops being a plugin at this moment). If you do that, remember to export all the symbols from the library that you want to be accessible in code using that library.

    Hello wysota thanks for your prompt reply.
    1.- THe pro file that i posted is for the applicationn
    2.- The pro file for my plugin is:

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += qt plugin
    3. QT += declarative
    4.  
    5. DESTDIR += ../plugins
    6. OBJECTS_DIR = tmp
    7. MOC_DIR = tmp
    8.  
    9. TARGET = FileDialog
    10.  
    11. HEADERS += directory.h \
    12. file.h \
    13. dialogPlugin.h
    14.  
    15. SOURCES += directory.cpp \
    16. file.cpp \
    17. dialogPlugin.cpp
    To copy to clipboard, switch view to plain text mode 

    I'm not sure wether I'm developing a qt plugin or a shared library. But I'm sure I'm trying to implement this modulehttp://qt-project.org/doc/qt-5.0/qtd...tartedqml.html

    3.- Directory is a class defined in the plugin This is the code for the headers of the plugin:

    the source code for dialogPlugin.h is:
    Qt Code:
    1. #ifndef DIALOGPLUGIN_H
    2. #define DIALOGPLUGIN_H
    3.  
    4. #include <QtDeclarative/QDeclarativeExtensionPlugin>
    5.  
    6. class DialogPlugin : public QDeclarativeExtensionPlugin
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. //registerTypes is inherited from QDeclarativeExtensionPlugin
    12. void registerTypes(const char *uri);
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 

    Source code for DialogPlugin.cpp (This is the only class that exports something)
    Qt Code:
    1. #include "dialogPlugin.h"
    2. #include "directory.h"
    3. #include "file.h"
    4. #include <QtDeclarative/qdeclarative.h>
    5.  
    6. void DialogPlugin::registerTypes(const char *uri)
    7. {
    8. //register the class Directory into QML as a "Directory" element version 1.0
    9. qmlRegisterType<Directory>(uri, 1, 0, "Directory");
    10. qmlRegisterType<File>(uri,1,0,"File");
    11. }
    12.  
    13. //FileDialog is the plugin name (same as the TARGET in the project file) and DialogPlugin is the plugin classs
    14. Q_EXPORT_PLUGIN2(FileDialog, DialogPlugin);
    To copy to clipboard, switch view to plain text mode 


    Source code in Directory.h, this module create some variables accessible form QML via Q_PROPERTY
    Qt Code:
    1. #ifndef DIRECTORY_H
    2. #define DIRECTORY_H
    3.  
    4. #include "file.h"
    5.  
    6. #include <QDir>
    7. #include <QStringList>
    8. #include <QTextStream>
    9. #include <QDeclarativeListProperty>
    10. #include <QObject>
    11.  
    12. class Directory : public QObject {
    13.  
    14. Q_OBJECT
    15.  
    16. //number of files in the directory
    17. Q_PROPERTY(int filesCount READ filesCount)
    18.  
    19. //list property containing file names as QString
    20. Q_PROPERTY(QDeclarativeListProperty<File> files READ files CONSTANT )
    21.  
    22. //file name of the text file to read/write
    23. Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
    24.  
    25. //text content of the file
    26. Q_PROPERTY(QString fileContent READ fileContent WRITE setFileContent NOTIFY fileContentChanged)
    27.  
    28. public:
    29. Directory(QObject *parent = 0);
    30.  
    31. //properties' read functions
    32. int filesCount() const;
    33. QString filename() const;
    34. QString fileContent() const;
    35. QDeclarativeListProperty<File> files();
    36.  
    37. //properties' write functions
    38. void setFilename(const QString &str);
    39. void setFileContent(const QString &str);
    40.  
    41. //accessible from QML
    42. Q_INVOKABLE void saveFile();
    43. Q_INVOKABLE void loadFile();
    44.  
    45. signals:
    46. void directoryChanged();
    47. void filenameChanged();
    48. void fileContentChanged();
    49.  
    50. private:
    51. QDir m_dir;
    52. QStringList m_dirFiles;
    53. File currentFile;
    54. QString m_saveDir;
    55. QStringList m_filterList;
    56.  
    57. //contains the file data in QString format
    58. QString m_fileContent;
    59.  
    60. //Registered to QML in a plugin. Accessible from QML as a property of Directory
    61. QList<File *> m_fileList;
    62.  
    63. //refresh content of the directory
    64. void refresh();
    65. };
    To copy to clipboard, switch view to plain text mode 

    Source code for directory.cpp, only normal C++ source code without exports.
    Qt Code:
    1. #include "directory.h"
    2. #include <QDebug>
    3.  
    4. /*
    5. Directory constructor
    6.  
    7. Initialize the saves directory and creates the file list
    8. */
    9. Directory::Directory(QObject *parent) : QObject(parent)
    10. {
    11. m_dir.cd( QDir::currentPath() );
    12.  
    13. //go to the saved directory. if not found, create save directory
    14. m_saveDir = "saves";
    15. if ( m_dir.cd(m_saveDir) == 0 ) {
    16. m_dir.mkdir(m_saveDir);
    17. m_dir.cd(m_saveDir);
    18. }
    19. m_filterList << "*.txt";
    20. refresh();
    21. }
    22.  
    23. /*
    24. Directory::filesNumber
    25. Return the number of Files
    26. */
    27. int Directory::filesCount() const
    28. {
    29. return m_fileList.size();
    30. }
    31.  
    32. /*
    33. Function called to append data onto list property
    34. */
    35. void appendFiles(QDeclarativeListProperty<File> * property, File * file)
    36. {
    37. Q_UNUSED(property);
    38. Q_UNUSED(file);
    39. //Do nothing. can't add to a directory using this method
    40. }
    41.  
    42. /*
    43. Function called to retrieve file in the list using an index
    44. */
    45. File* fileAt(QDeclarativeListProperty<File> * property, int index)
    46. {
    47. return static_cast< QList<File *> *>(property->data)->at(index);
    48. }
    49.  
    50. /*
    51. Returns the number of files in the list
    52. */
    53. int filesSize(QDeclarativeListProperty<File> * property)
    54. {
    55. return static_cast< QList<File *> *>(property->data)->size();
    56. }
    57.  
    58. /*
    59. Function called to empty the list property contents
    60. */
    61. void clearFilesPtr(QDeclarativeListProperty<File> *property)
    62. {
    63. return static_cast< QList<File *> *>(property->data)->clear();
    64. }
    65.  
    66. /*
    67. Returns the list of files as a QDeclarativeListProperty.
    68. */
    69. QDeclarativeListProperty<File> Directory::files()
    70. {
    71. refresh();
    72. return QDeclarativeListProperty<File>( this, &m_fileList, &appendFiles, &filesSize, &fileAt, &clearFilesPtr );
    73. }
    74.  
    75. /*
    76. Return the name of the currently selected file
    77. */
    78. QString Directory::filename() const
    79. {
    80. return currentFile.name();
    81. }
    82.  
    83. /*
    84. Return the file's content as a string.
    85. */
    86. QString Directory::fileContent() const
    87. {
    88. return m_fileContent;
    89. }
    90.  
    91. /*
    92. Set the file name of the current file
    93. */
    94. void Directory::setFilename(const QString &str)
    95. {
    96. if( str != currentFile.name() ) {
    97. currentFile.setName(str);
    98. emit filenameChanged();
    99. }
    100. }
    101.  
    102. /*
    103. Set the content of the file as a string
    104. */
    105. void Directory::setFileContent(const QString &str)
    106. {
    107. if(str != m_fileContent){
    108. m_fileContent = str;
    109. emit fileContentChanged();
    110. }
    111. }
    112.  
    113. /*
    114. Called from QML to save the file using the filename and file content.
    115. Saving makes sure that the file has a .txt extension.
    116. */
    117. void Directory::saveFile()
    118. {
    119. if(currentFile.name().size() == 0){
    120. qWarning()<< "Empty filename. no save";
    121. return;
    122. }
    123. QString extendedName = currentFile.name();
    124. if(!currentFile.name().endsWith(".txt")){
    125. extendedName.append(".txt");
    126. }
    127. QFile file( m_dir.filePath(extendedName) );
    128. if ( file.open(QFile::WriteOnly | QFile::Truncate) ) {
    129. QTextStream outStream(&file);
    130. outStream << m_fileContent;
    131. }
    132. file.close();
    133. refresh();
    134. emit directoryChanged();
    135. }
    136.  
    137. /*
    138. Load the contents of a file.
    139. Only loads files with a .txt extension
    140. */
    141. void Directory::loadFile()
    142. {
    143. m_fileContent.clear();
    144. QString extendedName = currentFile.name();
    145. if( !currentFile.name().endsWith(".txt") ) {
    146. extendedName.append(".txt");
    147. }
    148.  
    149. QFile file( m_dir.filePath(extendedName) );
    150. if ( file.open(QFile::ReadOnly ) ) {
    151. QTextStream inStream(&file);
    152.  
    153. QString line;
    154. do {
    155. line = inStream.read(75);
    156. m_fileContent.append(line);
    157. } while ( !line.isNull() ) ;
    158. }
    159. file.close();
    160. }
    161.  
    162. /*
    163. Reloads the content of the files list. This is to ensure that the newly
    164. created files are added onto the list.
    165. */
    166. void Directory::refresh()
    167. {
    168. m_dirFiles = m_dir.entryList(m_filterList,QDir::Files,QDir::Name);
    169. m_fileList.clear();
    170.  
    171. File * file;
    172. for(int i = 0; i < m_dirFiles.size() ; i ++) {
    173. file = new File();
    174.  
    175. if( m_dirFiles.at(i).endsWith(".txt") ) {
    176. QString name = m_dirFiles.at(i);
    177. file->setName( name.remove(".txt",Qt::CaseSensitive) );
    178. }
    179. else {
    180. file->setName(m_dirFiles.at(i));
    181. }
    182. m_fileList.append(file);
    183. }
    184. }
    To copy to clipboard, switch view to plain text mode 



    source code in file.h
    Qt Code:
    1. #include <QString>
    2. #include <QObject>
    3.  
    4. class File : public QObject{
    5.  
    6. Q_OBJECT
    7.  
    8. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    9.  
    10. public:
    11. File(QObject *parent = 0);
    12.  
    13. QString name() const;
    14. void setName(const QString &str);
    15.  
    16. signals:
    17. void nameChanged();
    18.  
    19. private:
    20. QString m_name;
    21. };
    To copy to clipboard, switch view to plain text mode 

    source code for file.cpp
    Qt Code:
    1. #include "file.h"
    2.  
    3. File::File(QObject *parent) : QObject(parent)
    4. {
    5. m_name = "";
    6. }
    7.  
    8. QString File::name() const{
    9. return m_name;
    10. }
    11. void File::setName(const QString &str){
    12. if(str != m_name){
    13. m_name = str;
    14. emit nameChanged();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    As you could see I'm trying to expand QML functionality through plugins as the examples "getting started", previously quoted proposes.

    Thanks for your help, I appreciate it a lot.

    Ulises Vega

Similar Threads

  1. Replies: 7
    Last Post: 11th April 2013, 10:55
  2. Link to plugin as dynamic lib in another plugin
    By alizadeh91 in forum Installation and Deployment
    Replies: 5
    Last Post: 16th December 2012, 22:16
  3. Replies: 1
    Last Post: 8th October 2010, 11:38
  4. Plugin and shared class between plugin and application
    By wishper in forum Qt Programming
    Replies: 7
    Last Post: 23rd August 2010, 17:00
  5. Replies: 0
    Last Post: 16th September 2009, 02:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.