标签:
由于Ubuntu手机平台安全的限制,在Ubuntu手机的应用中我们只能访问自己的空间.如果我们所需要访问的文件不存在于我们应用所在的空间,我们是没有办法访问到的.我们的应用只能访问系统提供的库.如果系统没有所需要的库的话,我们通过可以通过如下的方法实现:$ git clone https://github.com/liu-xiao-guo/studentlib_shared
#include<string>
class Student{
private:
std::string name;
public:
Student(std::string);
virtual void display();
};
#include <iostream>
#include "Student.h"
using namespace std;
Student::Student(string name):name(name){}
void Student::display(){
cout << "A student with name " << this->name << endl;
}
$ click chroot -aarmhf -fubuntu-sdk-15.04 run
$ mkdir build $ cd build $ cmake .. $ make
(click-ubuntu-sdk-15.04-armhf)liuxg@liuxg:~/qml/studentlib_shared/build$ ls CMakeCache.txt CMakeFiles Makefile cmake_install.cmake libtestStudent.so (click-ubuntu-sdk-15.04-armhf)liuxg@liuxg:~/qml/studentlib_shared/build$
#ifndef MYTYPE_H
#define MYTYPE_H
#include <QObject>
class MyType : public QObject
{
Q_OBJECT
Q_PROPERTY( QString helloWorld READ helloWorld WRITE setHelloWorld NOTIFY helloWorldChanged )
public:
explicit MyType(QObject *parent = 0);
Q_INVOKABLE void testlib();
~MyType();
Q_SIGNALS:
void helloWorldChanged();
protected:
QString helloWorld() { return m_message; }
void setHelloWorld(QString msg) { m_message = msg; Q_EMIT helloWorldChanged(); }
QString m_message;
};
#endif // MYTYPE_H
#include "mytype.h"
#include "Student.h"
MyType::MyType(QObject *parent) :
QObject(parent),
m_message("")
{
}
void MyType::testlib()
{
Student student("johnddfsfdfdfds");
student.display();
}
MyType::~MyType() {
}
liuxg@liuxg:~/qml/testplugin$ tree -L 3 . ├── backend │ ├── Testplugin │ │ ├── backend.cpp │ │ ├── backend.h │ │ ├── mytype.cpp │ │ ├── mytype.h │ │ ├── qmldir │ │ └── Testplugin.pro │ └── tests │ └── unit ├── libs │ ├── libs.pro │ ├── libtestStudent.so │ └── Student.h ├── manifest.json.in ├── po │ └── testplugin.liu-xiao-guo.pot ├── testplugin │ ├── Main.qml │ ├── testplugin.apparmor │ ├── testplugin.desktop │ ├── testplugin.png │ ├── testplugin.pro │ └── tests │ ├── autopilot │ └── unit ├── testplugin.pro └── testplugin.pro.user
TEMPLATE = lib
load(ubuntu-click)
filetypes = qml png svg js qmltheme jpg qmlproject desktop wav so
OTHER_FILES = filetypes
for(filetype, filetypes) {
OTHER_FILES += *.$$filetype
}
other_files.path = $${UBUNTU_CLICK_PLUGIN_PATH}
other_files.files = $$OTHER_FILES
INSTALLS += other_files
message(The project1 will be installed in $${UBUNTU_CLICK_PLUGIN_PATH})
SUBDIRS += testplugin backend/Testplugin libs
LIBS += -L$$PWD/../../libs/ -ltestStudent INCLUDEPATH += $$PWD/../../libs DEPENDPATH += $$PWD/../../libs
...
Button {
anchors.centerIn: parent
text: "Test lib"
onClicked: {
myType.testlib();
}
}
...$ adb shell
/opt/click.ubuntu.com/testplugin.liu-xiao-guo/current/lib/arm-linux-gnueabihf/
Student student("johnddfsfdfdfds");
student.display();标签:
原文地址:http://blog.csdn.net/ubuntutouch/article/details/51350867