新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Qt on Android:使用JNI與第三方j(luò)ar包

Qt on Android:使用JNI與第三方j(luò)ar包

作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò) 收藏

QHBoxLayout *getLayout = new QHBoxLayout();

layout->addLayout(getLayout);

m_urlEdit = new QLineEdit(http://blog.csdn.net/foruok);

getLayout->addWidget(m_urlEdit, 1);

QPushButton *getButton = new QPushButton(GET);

getLayout->addWidget(getButton);

connect(getButton, SIGNAL(clicked()), this, SLOT(onGet()));

m_resultView = new QTextEdit();

m_resultView->setReadOnly(true);

layout->addWidget(m_resultView, 1);

m_stateLabel = new QLabel();

layout->addWidget(m_stateLabel);

}

Widget::~Widget()

{

}

bool Widget::event(QEvent *e)

{

if(e->type() == SimpleCustomEvent::eventType())

{

e->accept();

SimpleCustomEvent *sce = (SimpleCustomEvent*)e;

switch(sce->m_arg1)

{

case 1:

m_resultView->setText(sce->m_arg2);

m_stateLabel->setText(Success!);

break;

case 0:

m_resultView->setText(sce->m_arg2);

m_stateLabel->setText(Failed!);

break;

case -1:

m_stateLabel->setText(sce->m_arg2);

break;

}

return true;

}

return QWidget::event(e);

}

void Widget::onGet()

{

#ifdef WIN32

m_resultView->setText(Sorry, Just for Android!);

#elif defined(ANDROID)

QString url = m_urlEdit->text();

QAndroidJniObject javaAction = QAndroidJniObject::fromString(url);

QAndroidJniObject::callStaticMethod(an/qt/useJar/ExtendsQtWithJava,

downloadWebPage,

(Ljava/lang/String;)V,

javaAction.object());

m_stateLabel->setText(Downloading...);

#endif

}

調(diào)用Java的代碼在onGet()槽中,很簡(jiǎn)單,不解釋了。有疑問(wèn)看Qt幫助手冊(cè)有關(guān)QAndroidJniObject類的說(shuō)明。

OK,到此結(jié)束。


上一頁(yè) 1 2 3 下一頁(yè)

關(guān)鍵詞:

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉