pikopong

it's all about knowledge

Archive for the ‘programming’ Category

How to enable MySQL support in Qt SDK for Linux

with 3 comments

  1. Download Qt SDK for Linux/X11 at Qt Software.
  2. Install it anywhere you want, just make sure you remember the path.
  3. To build MySQL as a plugin, you need to know two other paths:
    • Your MySQL header files directory. It should be something like this:
      decimal.h   m_string.h      my_dbug.h    my_list.h        my_sys.h     mysql_embed.h    mysqld_error.h  sql_state.h        typelib.h
      errmsg.h    my_alloc.h      my_dir.h     my_net.h         my_xml.h     mysql_time.h     raid.h          sslopt-case.h
      keycache.h  my_attribute.h  my_getopt.h  my_no_pthread.h  mysql.h      mysql_version.h  readline.h      sslopt-longopts.h
      m_ctype.h   my_config.h     my_global.h  my_pthread.h     mysql_com.h  mysqld_ername.h  sql_common.h    sslopt-vars.h
    • Your MySQL lib files directory. Something like this:
      libdbug.a    libmyisammrg.a      libmysqlclient.so@         libmysqlclient_r.a    libmysqlclient_r.so.15@      libmysys.a
      libheap.a    libmysqlclient.a    libmysqlclient.so.15@      libmysqlclient_r.la*  libmysqlclient_r.so.15.0.0*  libvio.a
      libmyisam.a  libmysqlclient.la*  libmysqlclient.so.15.0.0*  libmysqlclient_r.so@  libmystrings.a
  4. For Slackware 12.2, it should be:
    1
    2
    
    /usr/include/mysql	# MySQL header directory
    /usr/lib/mysql		# MySQL libraries
  5. Go to your Qt SDK installation directory, mine is: /opt/qtsdk-2009.03/
    1
    2
    3
    4
    5
    6
    
    cd /opt/qtsdk-2009.03/
    cd qt/src/plugins/sqldrivers/mysql/
    # Replace all the path based on your computer environment. 
    # Make sure 'qmake' can be run from anywhere or you'd have to specify the full path for it.
    qmake -o Makefile "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient" mysql.pro
    make
  6. You should have new files created for you:
    Makefile
    README
    libqsqlmysql.so*
    main.cpp
    main.o
    moc_qsql_mysql.cpp
    moc_qsql_mysql.o
    mysql.pro
    qsql_mysql.moc
    qsql_mysql.o
  7. Copy MySQL plugin to your Qt’s plugins directory,
    cp libqsqlmysql.so /opt/qtsdk-2009.03/qt/plugins/sqldrivers
  8. Create new project and put these codes to test your new plugin
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    #include <QCoreApplication>
    #include <QtSql>
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
     
        qDebug() << QSqlDatabase::drivers();
     
        return a.exec();
    }

    You’ll get these outputs showing that your Qt has supports for MySQL

    ("QSQLITE", "QMYSQL3", "QMYSQL")

Written by amree

July 22nd, 2009 at 3:21 pm

Posted in programming

Reading Mifare 1K Card using Java in Linux

with 37 comments

At the end of last year, my friends and I were tasked to read our staff card. The main objective was pretty simple, to create a library where we don’t have to depend on the vendor everytime we want to read our own staff card and the library should also be working on Windows and Linux (that means Java to us).

Working Environment

  1. Slackware 12.2
  2. JDK 6 Update 11
  3. Netbeans 6.5
  4. libusb 0.1.12
  5. Windows Binary of JPC/SC Java API 0.8.0
  6. Your contactless smartcard reader’s driver

Read the rest of this entry »

Written by amree

February 11th, 2009 at 4:27 pm

Posted in programming

Auto Resize JTable Column Width

with 10 comments

This code should resize your JTable column width based on the contents of the header and data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    public JTable autoResizeColWidth(JTable table, DefaultTableModel model) {
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setModel(model);
 
        int margin = 5;
 
        for (int i = 0; i < table.getColumnCount(); i++) {
            int                     vColIndex = i;
            DefaultTableColumnModel colModel  = (DefaultTableColumnModel) table.getColumnModel();
            TableColumn             col       = colModel.getColumn(vColIndex);
            int                     width     = 0;
 
            // Get width of column header
            TableCellRenderer renderer = col.getHeaderRenderer();
 
            if (renderer == null) {
                renderer = table.getTableHeader().getDefaultRenderer();
            }
 
            Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
 
            width = comp.getPreferredSize().width;
 
            // Get maximum width of column data
            for (int r = 0; r < table.getRowCount(); r++) {
                renderer = table.getCellRenderer(r, vColIndex);
                comp     = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false,
                        r, vColIndex);
                width = Math.max(width, comp.getPreferredSize().width);
            }
 
            // Add margin
            width += 2 * margin;
 
            // Set the width
            col.setPreferredWidth(width);
        }
 
        ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(
            SwingConstants.LEFT);
 
        // table.setAutoCreateRowSorter(true);
        table.getTableHeader().setReorderingAllowed(false);
 
        return table;
    }

Example:

1
2
3
// Must pass the model
DefaultTableModel model = new DefaultTableModel();
jTable = autoResizeColWidth(jTable, model);

Tested on JRE v5 and JRE v6

Written by amree

August 13th, 2008 at 2:49 pm

Posted in programming

Reading MyKad using Visual Basic

with 9 comments

It seems that a lot of people asking how to read MyKad using Visual Basic, but since I don’t have the slightest idea on how to code in VB, I started to search around. To my surprise, Xenon (the one who reverse engineered MyKad to get the APDU) actually wrote a small application in VB to read MyKad. So, for those who can’t afford to buy SDK from commercial company, you can download the code here for FREE !

VB Application to read MyKad


View the discussion
Download the code

Written by amree

May 28th, 2008 at 12:32 am

Posted in programming

Printing to Zebra S4M Using Java and ZPL II

with 15 comments

Apparently there’re some codes scattered on the net telling people that you can print to a Zebra printer by sending ZPL II codes using PrintService. But the problem is, it’s not working, I don’t know why, maybe because of a different version of printer or model but I’m pretty sure the thing that came out from the printer is just ordinary text not barcode which is what the code was supposed to output.

UPDATE: Problem solved and we know have 3 ways in printing using Zebra S4M
Read the rest of this entry »

Written by amree

May 11th, 2008 at 9:44 am

Posted in programming