2013-11-23

Using sqlite in Qt Application



 I got this error, every time a reopen or open a new database file:
 
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

Sometimes I get lazy and ask google first. This time google didn't tell me.
 A few noobs like me had the same issue. There was discussion about that, but they actually was digging to deep!

The answer is very simple!

Load driver only once:

QSqlDatabase::addDatabase("QSQLITE");

And then, the database file you can close and open multiple times:

db.setDatabaseName("myDatabase.sqlite");

if (db.open())
{
qDebug() << db.lastError();

}
else
{
qDebug() << db.tables();
}


db.close();




2013-11-20

Bash script to manage sshfs


If you wanna use sshfs, this software should be installed:


$apt-get install openssh-client openssh-server sshfs 

If server not always online and you want to mount automatically sshfs when server online, I use this bash.

Bud before running bash, you have to be able connect to server without a password.

You have to create pabulic key on client

$ssh-keygen -t rsa

And then copy key from client ~/.id_rsa.pub (single long line in the text file)
to server ~/.ssh/authorized_keys 

I added this script to "Startup Applications".


Download sshfs.bash

#!/bin/bash

echo $0

# =======================================================
# CONFIGURATION
REMOTE_IP="192.168.1.2"
REMOTE_USER="user"
REMOTE_PATH="/home/"
MOUNT_POINT="/media/sshfs/"

# =======================================================
# VARIABLES
BOOL_ONLINE=0
BOOL_MOUNTED=0
BOOL_PID_RUN=0
# =======================================================
# FUNCTIONS


FUNC_remote_net_stat()
{
NET_STATUS=`ping ${REMOTE_IP} -c 1`

    if grep -q "64 bytes from ${REMOTE_IP}: icmp_req=1 ttl=64 time=" <<< "$NET_STATUS" ; then
        echo "ONLINE"
        BOOL_ONLINE=1
        else
        echo "OFFLINE"
        BOOL_ONLINE=0
    fi
}


FUNC_pid_status()
{
PID_STAT=`ps axu`

    if grep -q "sshfs ${REMOTE_USER}@${REMOTE_IP}:${REMOTE_PATH}" <<< "$PID_STAT" ; then
        BOOL_PID_RUN=1
        echo "PID RUNNING"
        else
        BOOL_PID_RUN=0
        echo "PID DEAD"
    fi
}

# =======================================================
# SCIPT BODY


    while true
    do
        FUNC_remote_net_stat
        FUNC_pid_status
       
        if [ $BOOL_ONLINE -eq "1" ]; then
       
       
            if [ $BOOL_PID_RUN -eq "1" ]; then
            BOOL_MOUNTED=1
            fi
       
            if [ $BOOL_MOUNTED -eq "0" ]; then
            echo "MOUNTIN SSHFS ..."
   
            SSH_MOUNT=`sshfs ${REMOTE_USER}@${REMOTE_IP}:${REMOTE_PATH} ${MOUNT_POINT}`

                if [ ! -z "$SSH_MOUNT" ]; then
                echo "ERROR ${SSH_MOUNT}"
                else
                BOOL_MOUNTED=1
                fi
            echo "DONE"    
            fi   
        fi
       
       
        if [ $BOOL_ONLINE -eq "0" ]; then
       
            if [ $BOOL_MOUNTED -eq "1" ]; then
            echo "KILLING SSHFS ..."
            kill `pidof ssh`
            BOOL_MOUNTED=0
            echo "DONE"
            fi
        fi
       
        if [ $BOOL_MOUNTED -eq "1" ]; then
       
            if [ $BOOL_PID_RUN -eq "0" ]; then
            BOOL_MOUNTED=0
            fi
        fi       
       
    sleep 5
   
   
    done


echo "EXIT"

# THE END
# =======================================================

2013-11-12

Linus Torvalds Interviews






Desktop Environment's for Linux MINT



KDE

http://kde.org/
http://www.youtube.com/watch?v=3zpdjySiS88
http://www.youtube.com/watch?v=dohhz91OTPY

  It looks really cool, bud too much sparkles for every day work...

Cinnamon
http://segfault.linuxmint.com
  Today looks best! I did try Mint cinnamon 16.
The Ideas I like a lot!
* Great art work.
* Work space switcher by the mouse in the top left corner.
* Managing windows by dragging them to the sides or top.
Very useful features.
Bud sorry it's to buggy...
* Unable connect to hidden Wifi, Network settings window crash every time.
* I try organize panel content - unsuccessful.
* Some thing wrong with the package manager (I believe it's fixable).
Experience was similar to Ubuntu bugs in the passed, it was Ubuntu version 12.10 (don't know how it is now).
So I guess I have to wait for more stable Cinnamon, and stick to Mate for now. 


MATE
http://mate-desktop.org/
  Good! I enjoy it! (Mint 14)

I try live Mint Mate 16 - still great!
Unfortunately installation has some issues.
* Proprietary Drivers Installer works, bud nviadia xconfig tool not.
* there are some issue with desktop fonts when nvidia driver is activated.

* Have to fix repository list, for some reason live version repository list are different from installed version (Cinnamon 16 has the same issue). 


Gnome (not available with Mint)
http://www.gnome.org/
https://www.youtube.com/watch?v=fVQjEtZAkPk&feature=c4-overview-vl&list=PLT98CRl2KxKESwFYdodPEZ42M38c40_3f
Looks better last realise, bud BIG NO! I don't like the idea!
Touch screen menu doesn't help you work
faster or easier on non touch screen PC!  
Gnome plans integrate all social web like facebook and etc... to desktop environment, I never going to be interested in that! 


XFCE
http://www.xfce.org/
I don't know yet... Have to read & see more...


P.S. "The thing that works for every case it actually does not work in any case!" OR "What is suitable for everything, often is good for nothing...".

The same menu for touchscreen and for non touchscreen PC is just stupid!
At least I did not see good one yet...  I believe it should be two different work modes. It would be great if they switch dynamically. Selecting the mode during installation it would be also not bad.