Forum DhammaCitta. Forum Diskusi Buddhis Indonesia

Komunitas => Ilmu Pengetahuan dan Teknologi => Teknologi Informasi => Topic started by: tesla on 13 December 2010, 05:51:00 PM

Title: Ask about Qt
Post by: tesla on 13 December 2010, 05:51:00 PM
kalau dari Qt Creator mau coba buat 1 file executable bagaimana? (bukan project, tp hanya 1 file .cpp)
Title: Re: Ask about Qt
Post by: Forte on 13 December 2010, 08:04:43 PM
belum pernah coba.. tetapi setahu gw, qt membutuhkan setidaknya 1 file pro dan 1 file cpp..
file pro itu berguna untuk menyimpan configurasi seperti apakah dijalankan dalam bentuk console / pake gui

misal kandungan yang ada di file .pro :
Code: [Select]
QT       += gui

TARGET = Apps
CONFIG   += app_bundle

TEMPLATE = app


SOURCES += main.cpp \
    apps.cpp

HEADERS += \
    apps.h


Title: Re: Ask about Qt
Post by: Forte on 13 December 2010, 08:08:06 PM
contoh file .cpp nya

Code: [Select]
#include <QtGui/QApplication>
#include <QMainWindow>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow *w = new QMainWindow();
    w->setWindowTitle("Hello World");
    w->show();

    return a.exec();
}

hasilnya nanti akan muncul kotak mainwindow dengan titlebar "Hello World"
Title: Re: Ask about Qt
Post by: Forte on 13 December 2010, 10:02:45 PM
Buat bahan belajar.. iseng2.. copas code paritta..

Code: (paritta.pro) [Select]
#-------------------------------------------------
#
# Project created by QtCreator 2010-12-08T20:23:02
#
#-------------------------------------------------

QT       += gui

TARGET = Paritta
CONFIG   += app_bundle

TEMPLATE = app


SOURCES += main.cpp \
    paritta.cpp

HEADERS += \
    paritta.h

Code: (paritta.h) [Select]
#ifndef PARITTA_H
#define PARITTA_H

#include <QMainWindow>

class QLabel;
class QMenuBar;
class QMenu;
class QAction;
class QListWidget;
class QTextEdit;
class QDockWidget;
class QDir;
class QString;

class MainWindow : public QMainWindow
{
    Q_OBJECT;

public :
        MainWindow();

private slots :
        void AboutClicked();
        void SelectFile();
        void RefreshList();

private :
        QListWidget *listwidget;
        QLabel *label;
        QMenuBar *menubar;
        QMenu *mfile;
        QMenu *mview;
        QAction *actabout;
        QAction *actrefresh;
        QAction *actquit;
        QTextEdit *textedit;
        QDockWidget *dockwidget;
        QDir *dir;
        QString curpath;
        QString curOS;
};



#endif // PARITTA_H
Title: Re: Ask about Qt
Post by: Forte on 13 December 2010, 10:04:23 PM
Code: (paritta.cpp) [Select]
#include <QtGui>
#include <QFile>
#include <QMessageBox>
#include "paritta.h"

MainWindow::MainWindow()
{
// Set Title
    this->setWindowTitle(tr("Paritta ver. 1.0"));

// Set Menu
    menubar = new QMenuBar();
    mfile = menubar->addMenu("&File");
    mview = menubar->addMenu("&View");
    actrefresh = mfile->addAction("&Refresh");
    actquit = mfile->addAction("&Quit");
    actabout = menubar->addAction("&About");

// Set ListWidget
    // Prepare listwidget
    dockwidget = new QDockWidget("List");
    curpath= QString(QDir::currentPath());
    dir = new QDir(curpath,"*.txt");
    dockwidget->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    listwidget = new QListWidget();
    listwidget->addItems(QStringList(dir->entryList()));
    dockwidget->setWidget(listwidget);
    mview->addAction(dockwidget->toggleViewAction());

// Set TextEdit
textedit = new QTextEdit();
textedit->setReadOnly(true);

// Connect

connect(actquit,SIGNAL(triggered()),this,SLOT(close()));
connect(actabout,SIGNAL(triggered()),this,SLOT(AboutClicked()));
connect(listwidget,SIGNAL(itemSelectionChanged()),this,SLOT(SelectFile()));
connect(actrefresh,SIGNAL(triggered()),this,SLOT(RefreshList()));

//Set dock,central widget,etc
this->setMenuBar(menubar);
this->setCentralWidget(textedit);
this->addDockWidget(Qt::LeftDockWidgetArea,dockwidget);
this->showMaximized();
};

void MainWindow::AboutClicked()
{
    QMessageBox::about(this, tr("About Application"),
             tr("Application    : Paritta ver. 1.0    \n\n"
                "Programmer  : Forte "));
};

void MainWindow::RefreshList()
{
listwidget->clear();
dir->refresh();
listwidget->addItems(QStringList(dir->entryList()));
}

void MainWindow::SelectFile()
{
    if (!curpath.endsWith("/") ) {curpath.append("/");};

    QFile rtffile(curpath+listwidget->currentItem()->text());
    if (!rtffile.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        return;
    }
textedit->setText(rtffile.readAll());
}

Code: (main.cpp) [Select]
#include <QApplication>
#include "paritta.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow *w = new MainWindow();
    w->show();

    return a.exec();
}

semuanya dibuat pake handcoded.. jadi gak ada *.ui nya :P

hasilnya seperti di atas..
Title: Re: Ask about Qt
Post by: Sunkmanitu Tanka Ob'waci on 14 December 2010, 07:38:02 AM
kalo mau compile 1 file, tinggal pake compiler dong.

misalnya compilernya g++

Code: [Select]
g++ main.cpp -o output_executable
Title: Re: Ask about Qt
Post by: Forte on 14 December 2010, 07:54:45 AM
berarti bukan pake qmake nya qt ? pake make aja kan ?
Title: Re: Ask about Qt
Post by: Indra on 14 December 2010, 08:11:37 AM
tanya: kenapa memilih Qt? alasan dan pertimbangannya?
Title: Re: Ask about Qt
Post by: Forte on 14 December 2010, 08:34:22 AM
tanya: kenapa memilih Qt? alasan dan pertimbangannya?
- cross platform (unix, windows, mac os)
- bisa belajar C++  :P
- applicable to mobile phone u/ symbian
- lebih cepat dibanding java
- kiblatnya emang lebih ke desktop seh.. :P
- diracuni karuna :))
- terus meracuni tesla :))
Title: Re: Ask about Qt
Post by: Indra on 14 December 2010, 08:40:11 AM
- cross platform (unix, windows, mac os)
- bisa belajar C++  :P
- applicable to mobile phone u/ symbian
- lebih cepat dibanding java
- kiblatnya emang lebih ke desktop seh.. :P
- diracuni karuna :))
- terus meracuni tesla :))


kalau dibandingkan dengan lazarus?
Title: Re: Ask about Qt
Post by: Sumedho on 14 December 2010, 08:47:47 AM
mending xcode >:D
Title: Re: Ask about Qt
Post by: Indra on 14 December 2010, 08:53:47 AM
mending xcode >:D

xcode bisa windows?
Title: Re: Ask about Qt
Post by: Forte on 14 December 2010, 09:01:04 AM
mending xcode >:D
xcode itu apa ?

kalau dibandingkan dengan lazarus?

lazarus free pascal ya.. mungkin tesla bisa kasih input.. soalnya makanannya dia tuh.. :P
Title: Re: Ask about Qt
Post by: Indra on 14 December 2010, 09:08:05 AM
xcode itu apa ?

lazarus free pascal ya.. mungkin tesla bisa kasih input.. soalnya makanannya dia tuh.. :P


xcode adalah development tools di OS X, exclusive di Mac, adakah equivalent compilernya untuk windows?

 [at] Tesla yg sudah memakai keduanya, mohon sharing pengalamannya
Title: Re: Ask about Qt
Post by: Sumedho on 14 December 2010, 09:09:05 AM
Xcode is a suite of tools for developing software on Mac OS X, developed by Apple. Xcode 3.2, the latest major version, is bundled with Mac OS X v10.6, but is not installed by default. Instead it must be installed from the Mac OS X DVD, or downloaded for free from the Apple website. The version that is currently available is 3.2.5 that comes with iOS SDK 4.2.
Title: Re: Ask about Qt
Post by: Indra on 14 December 2010, 09:11:33 AM
Xcode is a suite of tools for developing software on Mac OS X, developed by Apple. Xcode 3.2, the latest major version, is bundled with Mac OS X v10.6, but is not installed by default. Instead it must be installed from the Mac OS X DVD, or downloaded for free from the Apple website. The version that is currently available is 3.2.5 that comes with iOS SDK 4.2.

jadi satu2nya deveelopment tool untuk iPad dan iPhone adalah XCode? benarkah?
Title: Re: Ask about Qt
Post by: Sumedho on 14 December 2010, 09:21:20 AM
AFAIK, CMIIW
Title: Re: Ask about Qt
Post by: tesla on 14 December 2010, 10:31:07 AM
tanya: kenapa memilih Qt? alasan dan pertimbangannya?
kalau dibandingkan dengan lazarus?

yah free pascal bagus jg sih...
secara konsep sangat mirip dg c++
hanya beda simbol2
:=  =
= ==
<> !=
* ^ (pointer)
& var (passing by reference)
dst...

kebetulan saja gw lagi butuh library utk YMSG -- Yahoo Messenger...
di java ada, jYMSG yg sudah mati, dan di-fork menjadi openYMSG yg sudah oke tapi masih ada bug
udah coba implement di Lazarus (Pascal) dg library yg dibuat Devy TYMSG (orang indonesia lho)... oke lah, tapi library ini newborn... masih sedikit sekali capability nya... nge-list multi group contact masih lom bisa...
& kelihatanya authornya sudah tidak menaruh perhatian pada lib ini...
ada yg mantap tapi bayar...

skr masih pakai pascal sih, tapi udah melirik ke libyahoo2 (http://libyahoo2.sourceforge.net/)
dg pertimbangan library ini yg paling mature...

mengapa Qt? sebenarnya ga jelas jg mengapa Qt...
sebab C/C++ punya byk GUI Library dari yg cross plaf & yg tidak.
alangkah baiknya kalau bisa seperti lazarus yg punya abstraction layer utk memilih GUI Library yg dipakai. shg programmer ga usah pusingin GUI LIbrary nya...
sayangnya di C/C++ ga ada abstraction layer tsb...
jadi pilihannya mau ga mau sih pilih salah satu, dan baru ketemu Qt yg kayanya solid bgt.

kesemua di atas, sebenarnya saya lebih library dependant daripada IDE dependant...
jadi 1st priority adalah library, 2nd baru cari IDE yg bagus

mending xcode >:D

xcode bisa pakai pascal & qt kok... jadi tenang aja. tar kalau punya mac baru sentuh xcode :p
Title: Re: Ask about Qt
Post by: tesla on 14 December 2010, 02:58:09 PM
ga ada toggle button ya? (kurang pas kalau pakai checkbox
Title: Re: Ask about Qt
Post by: Forte on 14 December 2010, 09:54:42 PM
ga ada toggle button ya? (kurang pas kalau pakai checkbox
ada donk.. ;D
pake QPushButton

biar ngerti.. coba test code di bawah ini ;D

Code: (Toggle Button Tips) [Select]
#include <QtGui/QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *w = new QWidget();
    QVBoxLayout *layout = new QVBoxLayout();
    QPushButton *button = new QPushButton("Toggle");
    QPushButton *normal = new QPushButton("Normal");
    button->setCheckable(true);
    layout->addWidget(button);
    layout->addWidget(normal);
    w->setLayout(layout);
    w->show();
    return a.exec();
}
Title: Re: Ask about Qt
Post by: tesla on 16 December 2010, 05:36:23 PM
ada layout utk yg kalau window nya resize, widget nya ikut resize ga?
Title: Re: Ask about Qt
Post by: tesla on 16 December 2010, 05:44:50 PM
ada layout utk yg kalau window nya resize, widget nya ikut resize ga?

solved...