I am trying to understand how to build and compile a simple Qt project in C4Droid, the C ++ compiler for Android.
The program includes 2 simple examples: the "Hello world" shortcut (single file) and the Notepad example. The second seems interesting, but it concerns forms that create them entirely from code.
I am exploring if this is done with forms created from .ui files. I created a simple project in Qt Creator for Qt 4.8, compiled the .ui form, and adapted the code from Qt 4.8 to Qt 5.2. The project itself is very simple: a form with QButton and QLineEdit. When QButton is pressed, "Hello world" appears in QLineEdit.
As far as I saw, C4Droid does not parse .pro files. To compile the project, I have to open main.cpp and click “compile”, select “Compile multiple source code files (simple)”, and then run. C4droid uses its own makefile in a .c4droid text file.
These are the files that I published in the C4droid test folder:
ButtonHelloWorld.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ButtonHelloWorld
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
main.cpp:
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_ButtonSayHello_clicked();
private:
Ui::MainWindow *ui;
};
#endif
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_ButtonSayHello_clicked()
{
ui->LeditSayHello->setText(tr("Hello world"));
}
ui_mainwindow.h:
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QHeaderView>
#include <QLineEdit>
#include <QMainWindow>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QVBoxLayout *verticalLayout;
QPushButton *ButtonSayHello;
QLineEdit *LeditSayHello;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(198, 103);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
verticalLayout = new QVBoxLayout(centralWidget);
verticalLayout->setSpacing(6);
verticalLayout->setContentsMargins(11, 11, 11, 11);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
ButtonSayHello = new QPushButton(centralWidget);
ButtonSayHello->setObjectName(QString::fromUtf8("ButtonSayHello"));
verticalLayout->addWidget(ButtonSayHello);
LeditSayHello = new QLineEdit(centralWidget);
LeditSayHello->setObjectName(QString::fromUtf8("LeditSayHello"));
LeditSayHello->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(LeditSayHello);
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
}
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
ButtonSayHello->setText(QApplication::translate("MainWindow", "Say Hello", 0));
}
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
}
QT_END_NAMESPACE
#endif
I put the original mainwindow.ui here for reference (c4droid does not use it):
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>198</width>
<height>103</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="ButtonSayHello">
<property name="text">
<string>Say Hello</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="LeditSayHello">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
When I try to compile this project with main.cpp in C4droid, the output is:
/storage/emulated/0/Bull/C4Droid/ButtonHelloWorld/main.cpp:0: : . . /data/data/com.n0n3m4.droidc/files/gcc/tmpdir/ccyCC2RV.o: MainWindow::MainWindow(QWidget*)': mainwindow.cpp:(.text+0xc4):
undefined reference to vtable MainWindow ' /data/data/com.n0n3m4.droidc/files/gcc/tmpdir/ccyCC2RV.o: MainWindow::~MainWindow()': mainwindow.cpp:(.text+0x14c): undefined
reference to vtable MainWindow ' /data/data/com.n0n3m4.droidc/files/gcc/tmpdir/ccyCC2RV.o: MainWindow::tr(char const*, char const*, int)':
mainwindow.cpp:(.text._ZN10MainWindow2trEPKcS1_i[_ZN10MainWindow2trEPKcS1_i]+0x5c):
undefined reference to MainWindow:: staticMetaObject 'collect2: error: ld 1
, ?
, .moc, .
(, "C4Droid", : -/)
1
--- Qt , C4droid, , Makefile. Makefile, , :
/data/data/com.n0n3m4.droidc/files/gcc/qt/bin/qmake -spec android-g++ -o Makefile application.pro
( , moc, qmake, rcc uic /data/data/com.n0n3m4.droidc/files/gcc/qt/bin/ )
Makefile .pro, uic, moc .. . :
/data/data/com.n0n3m4.droidc/files/gcc/qt/bin/qmake -spec android-g++ -o Makefile ButtonHelloWorld.pro
, , :
sh: arm-linux-androideabi-gcc:
2
C4droid :
"C4droid .pro, . Google Play - , ".
, .pro C4droid. , "Makefile" Qt-, "ButtonHelloWorld.qexe" - .
, :
?
3
, () Qt appl. , .
:
. (/storage/emulated/0/Bull/C4Droid/application)
images folder
application.pro
application.qrc
main.cpp
mainwindow.cpp
mainwindow.h
, C4droid, application.pro, "". "Makefile" Qt-, "pplication.so". , " ".
"libapplication.so" , .
¿?
:
Android- Qt libXXX.so
:
, "libappli.so" .
, , , lib [NameOf.proFileWithoutExtension].so, . !
, .APK , Menu- > Export. ... !
. , .