Qt questions

I’ll pile up my questions in this thread.

Q number 1:

I have QString, I want to display “Pomoć” in menu. That last character is Serbian letter. It just comes out as rubbish.
Can I use QString and can it display UTF-8, and how?

Thanks.

beli0135 wrote:

>
> I’ll pile up my questions in this thread.
>
> Q number 1:
>
> I have QString, I want to display “Pomoć” in menu. That last
> character is Serbian letter. It just comes out as rubbish.
> Can I use QString and can it display UTF-8, and how?
>
> Thanks.

That should be a snap. QString and QChar are implemented to contain unicode
characters, and the Qt widgets are unicode aware.

I’m assuming that “ć” is an HTML encoding equating to the lowercase
C-acute character. Not surprisingly, the unicode for this character is
U+0107, which you can specify as QChar(0x0107). The entire string could be
coded as:
QString(“Pomo”)+QChar(0x0107)

Yea, worked, thanks. But isn’t it awkward that I have to do it this way? Can’t it just reckognize it from keyboard, I mean “pomoć”, as there are many characters that I’d have to do it this way.
Or my keyboard settings are not unicode?

beli0135 wrote:

>
> Yea, worked, thanks. But isn’t it awkward that I have to do it this
> way? Can’t it just reckognize it from keyboard, I mean “pomoć”, as
> there are many characters that I’d have to do it this way.
> Or my keyboard settings are not unicode?

As a matter of fact, YES! I think it is terribly awkward! I’ve run into
the same thing and have not (yet) found a more convenient way to initialize
a string of unicode characters. (However, see below for an alternate
idea.)

I doubt your keyword is unicode aware. I do not know of any that are. But
there are different keyboard mappings available that allow one to key
non-Ascii characters, especially Latin-1 characters such as the ones you
probably want.

OTOH, perhaps the problem is not with your keyboard, but with your editor!
For example, Open Office Writer has a function that allows you to “insert
special character”. It’s not exactly speed typing, but at least you can
insert Latin-1 characters visually, rather than having to look up some
obscure code number for it. Of course, OO Writer is not my first choice as
an editor for C++ source code, but I suspect there are other editors that
can do the same thing, or something similar.

this is interesting…
I have US-intl keyboard when I write in English and Portuguese, and I use Serbian latinunicode, for Serbian. I think both of them are unicode alright.
I see that unicode thing works properly with KWrite, so it is maybe Qt Creator’s editor that is middle-man with problem.

…maybe

Trivial question:
How to get items from QComboBox? Trivial as it seems, could not find function that will return them to me.
I have 3 items (text), and I just want them in, for example, QList.

Another: how to properly iterate through combo in runtime?

Arte you asking how to add items to a combobox? If so it’s pretty easy:

QStringList *mylist = new QStringList();                
mylist->append("Item One");
mylist->append("Item Two");
mylist->append("Item Three");
myComboBox->addItems(*mylist);
delete mylist;

For iterating over combobox items you can get the count and loop through the items. If you just want the item text use the itemText method of the combobox.

int max = myComboBox->count();

for ( int index = 0; index < max; index++ )
{
    QString item = myComboBox->itemText(index);  
}

Thank you. That is what I want :slight_smile:

I will go nuts!

This works:


QStringList filters;
filters << "*.jpg" << "*.png";
directory.setNameFilters(filters);

Following is giving me
ASSERT failure in QList::operator]: “index out of range”, file /usr/include/qt4/QtCore/qlist.h, line 403


this->fileTypes = "*.jpg";//QString
filters.append(this->fileTypes);
directory.setNameFilters(filters);

I would like to fill one QString with file types “.jpg;.png”;
do the “split()” and add them to filters.
Something like:


if (this->fileTypes.indexOf(";") != -1)
    {
        filters = this->fileTypes.split(";");
    }
    else
       filters.append(this->fileTypes);

beli0135 wrote:

>
> I will go nuts!
>
> This works:
>
> Code:
> --------------------
>
> QStringList filters;
> filters << “.jpg" << ".png”;
> directory.setNameFilters(filters);
>
> --------------------
>
>
> Following is giving me
> ASSERT failure in QList<T>::operator]: “index out of range”, file
> /usr/include/qt4/QtCore/qlist.h, line 403
>
>
> Code:
> --------------------
>
> this->fileTypes = “.jpg";//QString
> filters.append(this->fileTypes);
> directory.setNameFilters(filters);
>
> --------------------
>
>
>
> I would like to fill one QString with file types "
.jpg;*.png”;
> do the “split()” and add them to filters.
> Something like:
>
>
> Code:
> --------------------
>
> if (this->fileTypes.indexOf(";") != -1)
> {
> filters = this->fileTypes.split(";");
> }
> else
> filters.append(this->fileTypes);
>
> --------------------

I don’t see what is causing the ASSERT failure, but I assume it has
something to do with using append(). You can avoid that construct
completely. In your last example, you do not need to search for the
separator yourself. Replace all that with one line like this:

filters = this->fileTypes.split( “;”, QString::SkipEmptyParts );

If the separator is not found in the string, split() returns a
single-element list containing the whole string. I think that is what you
want, so don’t make it any harder than necessary.

(It’s probably not necessary, but I think it would be a good idea to use the
SkipEmptyParts behavior in this case.)

Thanks.

as I see, error is somewhere else… suddenly, Qt Creator stopped debugging as X does not let me run program from debugger (no permissions), but I can from command line…

strange.

How can I discover which language is on user’s system? (valid for all distros)

Hi,

I guess Qt 4.5.3: QLocale Class Reference is what you are looking for.

Hope this helps

Yap, that is it.
thanks

Anyone was/is using Qt on windows?

I installed XP on virtual machine, installed Qt 4.6.0, Qt Creator, MinGW… but when I compile project, it shows zillion errors like “undefined reference to ZHeuwWusjWuySj3WSju in main.cpp” I may be missing something, but I do not know what.

In linux works, of course.

Hi,

I guess we need some more informations on how you are compiling your project. It looks like some library path is not set correctly.

Maybe you can post the complete compiler output to something like pastebin. Someone then could have a clue what is missing.

OK, here it is… just to mention few things before.

In linux, all you have to do is compile and it works. I use Qt Creator as IDE, but can be compiled with qmake with no problem.

On clean XP (virtualbox), installed Qt 4.6, QtCreator, MinGW, executed build (on the same code that compiles and runs in linux) and I get:


Running build steps for project baires...
Configuration unchanged, skipping QMake step.
Starting: C:/dev/MinGW/bin/mingw32-make.exe debug -w 
mingw32-make: Entering directory `C:/projects/baires'
C:/dev/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/projects/baires'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\baires.exe debug/main.o debug/mainwindow.o debug/config.o debug/moc_mainwindow.o debug/moc_config.o -L"c:\dev\Qt\4.6.0\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
debug/main.o: In function `main':
/home/ebeli/Documents/projects/baires/baires/main.cpp:25: undefined reference to `ZN12QApplicationC1ERiPPci'
/home/ebeli/Documents/projects/baires/baires/main.cpp:26: undefined reference to `ZN10MainWindowC1EP7QWidget'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `ZN12QApplication4execEv'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `ZN10MainWindowD1Ev'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `ZN10MainWindowD1Ev'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `ZN12QApplicationD1Ev'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `ZN12QApplicationD1Ev'
/home/ebeli/Documents/projects/baires/baires/main.cpp:28: undefined reference to `Unwind_Resume'
debug/mainwindow.o: In function `ZN10MainWindowC2EP7QWidget':
C:/projects/baires/mainwindow.cpp:34: undefined reference to `vtable for MainWindow'
C:/projects/baires/mainwindow.cpp:34: undefined reference to `vtable for MainWindow'
debug/mainwindow.o: In function `ZN10MainWindowC1EP7QWidget':
C:/projects/baires/mainwindow.cpp:34: undefined reference to `vtable for MainWindow'
C:/projects/baires/mainwindow.cpp:34: undefined reference to `vtable for MainWindow'
debug/mainwindow.o: In function `ZN10MainWindowD2Ev':
C:/projects/baires/mainwindow.cpp:57: undefined reference to `vtable for MainWindow'
debug/mainwindow.o:C:/projects/baires/mainwindow.cpp:57: more undefined references to `vtable for MainWindow' follow
debug/mainwindow.o: In function `ZN10MainWindow28on_actionSe_ttings_triggeredEv':
C:/projects/baires/mainwindow.cpp:462: undefined reference to `config::config(QWidget*)'
C:/projects/baires/mainwindow.cpp:507: undefined reference to `config::~config()'
C:/projects/baires/mainwindow.cpp:507: undefined reference to `config::~config()'
debug/mainwindow.o: In function `ZNK9QListData5beginEv':
C:/projects/baires/../../dev/Qt/4.6.0/include/QtCore/../../src/corelib/tools/qlist.h:(.text$_ZN10MainWindow2trEPKcS1_[MainWindow::tr(char const*, char const*)]+0x1c): undefined reference to `MainWindow::staticMetaObject'
debug/config.o: In function `ZN6config20on_btnRemove_clickedEv':
/home/ebeli/Documents/projects/baires/baires/config.cpp:86: undefined reference to `ZNK11QListWidget11currentItemEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:88: undefined reference to `ZNK11QListWidget11currentItemEv'
debug/config.o: In function `ZN6config21on_buttonBox_acceptedEv':
/home/ebeli/Documents/projects/baires/baires/config.cpp:33: undefined reference to `ZNK15QAbstractButton9isCheckedEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:37: undefined reference to `ZNK15QAbstractButton9isCheckedEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:48: undefined reference to `ZNK15QAbstractButton9isCheckedEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:59: undefined reference to `ZNK15QAbstractButton9isCheckedEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:75: undefined reference to `ZNK11QListWidget4itemEi'
/home/ebeli/Documents/projects/baires/baires/config.cpp:73: undefined reference to `ZNK11QListWidget5countEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:77: undefined reference to `ZN9QSettingsC1ERK7QStringS2_P7QObject'
/home/ebeli/Documents/projects/baires/baires/config.cpp:77: undefined reference to `ZN9QSettingsD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:78: undefined reference to `ZN8QVariantC1ERK7QString'
/home/ebeli/Documents/projects/baires/baires/config.cpp:78: undefined reference to `ZN9QSettings8setValueERK7QStringRK8QVariant'
/home/ebeli/Documents/projects/baires/baires/config.cpp:78: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:78: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:79: undefined reference to `ZNK9QComboBox12currentIndexEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:79: undefined reference to `ZN8QVariantC1Ei'
/home/ebeli/Documents/projects/baires/baires/config.cpp:79: undefined reference to `ZN9QSettings8setValueERK7QStringRK8QVariant'
/home/ebeli/Documents/projects/baires/baires/config.cpp:79: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:79: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:80: undefined reference to `ZN8QVariantC1ERK7QString'
/home/ebeli/Documents/projects/baires/baires/config.cpp:80: undefined reference to `ZN9QSettings8setValueERK7QStringRK8QVariant'
/home/ebeli/Documents/projects/baires/baires/config.cpp:80: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:80: undefined reference to `ZN8QVariantD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:81: undefined reference to `ZN9QSettings4syncEv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:81: undefined reference to `ZN9QSettingsD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:81: undefined reference to `ZN9QSettingsD1Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:81: undefined reference to `Unwind_Resume'
debug/config.o: In function `~config':
/home/ebeli/Documents/projects/baires/baires/config.cpp:15: undefined reference to `ZdlPv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZN7QDialogD2Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZN7QDialogD2Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `Unwind_Resume'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZdlPv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:15: undefined reference to `ZdlPv'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZN7QDialogD2Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZN7QDialogD2Ev'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `Unwind_Resume'
/home/ebeli/Documents/projects/baires/baires/config.cpp:16: undefined reference to `ZdlPv'


[SNAPP -- cut some code due to length]

debug/moc_config.o:(.rodata._ZTV6config[_ZTV6config]+0x104): undefined reference to `ZThn8_NK7QWidget6metricEN12QPaintDevice17PaintDeviceMetricE'
debug/moc_config.o:(.rodata._ZTI6config[_ZTI6config]+0x0): undefined reference to `ZTVN10__cxxabiv120__si_class_type_infoE'
debug/moc_config.o:(.rodata._ZTI6config[_ZTI6config]+0x8): undefined reference to `ZTI7QDialog'
collect2: ld returned 1 exit status
mingw32-make[1]: Leaving directory `C:/projects/baires'
mingw32-make: Leaving directory `C:/projects/baires'
mingw32-make[1]: *** [debug\baires.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project baires
When executing build step 'Make'

Oh, I have seen that I have <include> to one inexisting file. Afer removing reference I get


Running build steps for project baires...
Configuration unchanged, skipping QMake step.
Starting: C:/dev/MinGW/bin/mingw32-make.exe debug -w 
mingw32-make: Entering directory `C:/projects/baires'
C:/dev/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/projects/baires'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\dev\Qt\4.6.0\include\QtCore" -I"..\..\dev\Qt\4.6.0\include\QtGui" -I"..\..\dev\Qt\4.6.0\include" -I"..\..\dev\Qt\4.6.0\include\ActiveQt" -I"debug" -I"." -I"..\..\dev\Qt\4.6.0\mkspecs\win32-g++" -o debug\mainwindow.o mainwindow.cpp
mainwindow.cpp: In constructor `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:32: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:34: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:35: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:36: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:37: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:38: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:39: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:48: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:48: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp: In destructor `virtual MainWindow::~MainWindow()':
mainwindow.cpp:59: warning: possible problem detected in invocation of delete operator:
mainwindow.cpp:59: warning: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: warning: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:59: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
mainwindow.cpp: In member function `void MainWindow::loadSettings()':
mainwindow.cpp:65: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:66: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:67: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:68: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:69: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:70: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:75: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:80: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:85: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:86: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:87: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:90: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:94: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:96: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:98: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:105: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:539: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:540: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mainwindow.cpp:541: error: invalid use of undefined type `struct Ui::MainWindowClass'
mainwindow.h:27: error: forward declaration of `struct Ui::MainWindowClass'
mingw32-make[1]: Leaving directory `C:/projects/baires'
mingw32-make: Leaving directory `C:/projects/baires'
mingw32-make[1]: *** [debug/mainwindow.o] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project baires
When executing build step 'Make'

I give up… not even clean project can compile…
Just made new->Qt application, named it test, and built… errors

Hi,

it looks like something goes wrong in the moc compiler. Have a look at Qt 4.6: Using the Meta-Object Compiler (moc)

Maybe the following suggestion helps:

If you get linkage errors in the final building phase of your program, saying that YourClass::className() is undefined or that YourClass lacks a vtable, something has been done wrong. Most often, you have forgotten to compile or #include the moc-generated C++ code, or (in the former case) include that object file in the link command. If you use qmake, try rerunning it to update your makefile. This should do the trick.

Hope this helps