QT isn't utf-8?

217 views
Skip to first unread message

Magdy Ragab

unread,
May 30, 2016, 5:15:55 PM5/30/16
to The Ring Programming Language
Hello ,
It looks like that QT isn't utf-8, 
under Windows it look the text is garbage and the out put looks like this 

╪د┘„┘„┘ç

which affects search in the databse
I'm sure that all files are in UTF-8, I've read this page 

I also tried to type in CMD this command
chcp 65001
Which is converting command prompt  character to unicode.
I suggest to add "trUtf8" function.


Mahmoud Fayed

unread,
May 31, 2016, 4:49:47 PM5/31/16
to The Ring Programming Language
Hello Magdy

Qt support UTF-8 very well 

Just provide more details about what you are doing

From where you get the data ?
What kind of process you are doing ?

Also i will check the Qt classes to see if we will need to add more classes to RingQt for this purpose.

Greetings,
Mahmoud

Magdy Ragab

unread,
May 31, 2016, 5:06:00 PM5/31/16
to The Ring Programming Language
Hello Mahmoud
Thanks for your response 
please have a look here

this about searching in SQLite db here


The same code works fine under linux 

Magdy Ragab

unread,
May 31, 2016, 5:12:26 PM5/31/16
to The Ring Programming Language

Mahmoud Fayed

unread,
Jun 1, 2016, 1:04:51 AM6/1/16
to The Ring Programming Language
Hello Magdy

The problem is related to the SQLite driver for windows

When you pass UTF-8 data in the query string 

Try search with writing values in the source code (without GUI) and you will get the same result
So the problem is not related to Qt

Also as you said it is working on Linux without problems.

Solution : Write a program to convert the SQLite database to Microsoft Access Database (mdb)
Then when the application works on windows, just change the connection string and connect to access instead of SQLite

I tested the access driver for ODBC and the search using UTF-8 strings works without problems

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Jun 1, 2016, 1:40:29 AM6/1/16
to The Ring Programming Language
Hello Magdy

Two other solutions to avoid converting the database

(1) Load the table content to Ring Array then search in the array 
Since the database is small - doing this will be fast (not a problem)

(2) Create new library that support SQLite without using ODBC (Need C Knowledge and Ring API)

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Jun 1, 2016, 4:13:28 AM6/1/16
to The Ring Programming Language
Hello Magdy

The next update to your code solve the problem without changing the database 

func searchindex
m= table2.setRowCount(0)
searchTextResult= searchtxtBox.text()
if searchTextResult != ''
qx= new QObject
q= "select * from Quran"
see q+nl
i=0
odbc_execute(pODBC, q)
while odbc_fetch(pODBC)
cleanAyatSearch=odbc_getdata(pODBC,9)
suraSearch=odbc_getdata(pODBC,8)
pageSearch=odbc_getdata(pODBC,4)
VerseIDSearch=odbc_getdata(pODBC,3)
                        // Here we do the filter !
IF NOT (SUBSTR(CleanAyatSearch,searchTextResult))
loop
ok
table2.insertRow(i)
it1=QTableWidgetItem_new(cleanAyatSearch)
it2=QTableWidgetItem_new(suraSearch)
it3=QTableWidgetItem_new(pageSearch)
it4=QTableWidgetItem_new(VerseIDSearch)
table2.setitem(i,0,it1)
table2.setitem(i,1,it2)
table2.setitem(i,2,it3)
table2.setitem(i,3,it4)
i++
end
else
dialogBoxOk("لم تقم بكتابة شئ للبحث عنه", MainWin)
ok


Greetings,
Mahmoud

Magdy Ragab

unread,
Jun 1, 2016, 9:27:10 PM6/1/16
to The Ring Programming Language
Hello Eng.Mahmoud 
Thanks for support; but I found another one (after two days of hard work to figure out how to solve it)

I've tried every thing you can imagine, from saving text to file and load it , to convert every character to it's ascii and use these ascii codes to search with ; to store it in a temporary table !
I even recreate the whole DB  with all data with different encoding (UTF-8,UTF-16,Latin 1 and Windows-1256)

while trying the last solution (Windows-1256) I found that I can search correctly but characters display as  'garbage'  text (but search works)
so I've update my DB table by adding other two fields (Windows-1256) to search and display other fields (UTF-8)!

I could use youur code but I've faced two problems
- the first it was a bit slow (think about searching by word 'الله')
- the second that I still need to search Sura name to save as bookmarks (which is for some reason is UTF-8 : searchable but don't display correctly)

Yes this solution has its cost (double size of table) but it's working.

I'm sharing this solution to every one  tries all of : (windows - QT - SQlite)

It will be nice if you provide and way to convert between encoding :)
this may save a lot of time

By the way I've created a new branch with all code including the new version of DB and some fixes

Mahmoud Fayed

unread,
Jun 1, 2016, 10:00:02 PM6/1/16
to The Ring Programming Language
Hello Magdy

What I'm going to do is providing native support for SQLite like MySQL
So we don't need to use ODBC or Drivers to connect to SQLite database
This way will be better and practical solution.

Greetings,
Mahmoud

Magdy Ragab

unread,
Jun 1, 2016, 10:02:31 PM6/1/16
to The Ring Programming Language
Hello
I've returned to tell you that character re-encoding should be part of ring (even if this may be version 2 of ring)
Why it should n't be QT?
coz simply we don't use qt in web or console application

Magdy Ragab

unread,
Jun 1, 2016, 11:16:30 PM6/1/16
to The Ring Programming Language
This will be a great solution, especially for Android application
Thanks

Mahmoud Fayed

unread,
Jun 2, 2016, 2:54:11 PM6/2/16
to The Ring Programming Language
Hello Magdy

Sure, for better Android support we need
(1) SQLite Extension for Ring
(2) Compiling application source files (*.ring) to one object file (Faster/Protect the source code)
(3) Qt project ready for adding our Ring project files then building for Android

Greetings,
Mahmoud

Magdy Ragab

unread,
Jun 3, 2016, 7:03:41 PM6/3/16
to The Ring Programming Language
Hello Mahmoud
yes protecting code is a good idea for commercial projects and it will attract more developers to learn Ring.

I can't wait to test these awesome new feature; but till then I'm happy with Ring :)

Mahmoud Fayed

unread,
Jun 4, 2016, 3:24:31 AM6/4/16
to ring...@googlegroups.com
Hello Magdy

Thanks for your kind words :D You are welcome :D

I have already added Qt Classes for interacting with the database
To be used in Desktop and Mobile Applications.

Rewrite your application code and create a class for everything that you do with the database
And become ready to replace odbc functions with the Qt classes methods

Also become ready to avoid using QWebView and use another control.

I will release Ring Project for Qt to build Ring applications for Mobile (Android/iPhone) very soon.

Greetings,
Mahmoud

Magdy Ragab

unread,
Jun 4, 2016, 10:18:39 AM6/4/16
to The Ring Programming Language
Hi
this mean that the new release is downloadable ? 

Mahmoud Fayed

unread,
Jun 5, 2016, 12:10:02 PM6/5/16
to The Ring Programming Language
Hello Magdy

Not released yet, I will release the update + Qt project for Ring Applications (Android) during the next 24 hours

Greetings,
Mahmoud

Magdy Ragab

unread,
Jun 5, 2016, 2:25:24 PM6/5/16
to The Ring Programming Language
let me borrow your words
keep up the good work :D

Mahmoud Fayed

unread,
Jun 6, 2016, 12:52:28 AM6/6/16
to The Ring Programming Language
Hello Magdy

Thanks for your kind words
You are welcome :D

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages