Results 1 to 8 of 8

Thread: QCcompleter , colum probelm

  1. #1
    Join Date
    Jan 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QCcompleter , colum probelm

    guys i want to make a lineEdit complete its field from a QTableModel colum , the problem that it completes from other colum not the one i choose
    Qt Code:
    1. QCompleter* cc = new QCompleter( this ) ;
    2. cc->setModel( model );
    3. cc->setCompletionColumn(2);
    4. cc->setCompletionMode(QCompleter::PopupCompletion);
    5. cc->setCaseSensitivity( Qt::CaseInsensitive );
    6. lineEdit->setCompleter(cc);
    To copy to clipboard, switch view to plain text mode 

    shouldn't it display colum 2 in the model ?
    it is displaying the colum 0 , the primary key!

  2. #2
    Join Date
    Jan 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCcompleter , colum probelm

    i m wrong about something ,
    the completer works fine , but the list which is popued up , works not fine.
    it works on the first coulm not on the second one..
    so the completer wroks fine but teh QListView which is created when "QCompleter::PopupCompletion" don't work fine?!!!

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCcompleter , colum probelm

    Could you provide a minimal compilable example reproducing the problem?

  4. #4
    Join Date
    Jan 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCompleter , colum probelm

    look i have a lineEdit.
    i want the line edit complete the words when the user type just the first letter of teh word.So i will use the QCompleter class to make this process.i want the words to be completed from a table in mysql server database.
    the words is in the colum number 2 in the table.
    i setup the completer class to use the table model , colum 2..
    that works fine , now when the user type the first letter of the word the completer class suggest the rest of the word by searching the table in the colum i specified.But the problem arise when the Qcompleter display a list of strings to the user to choose his word from..instead of using the strings found in the colum 2 ,which i told about later , the list display strings from another colum.
    i don't know how to explain more than this

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCompleter , colum probelm

    Quote Originally Posted by deepinlife View Post
    i don't know how to explain more than this
    Provide a compilable piece of code reproducing the problem. Without seeing the actual code which I can run, I have no way of telling what you did wrong (if you did something wrong at all). The snippet you provided is too small to have the full picture.

  6. #6
    Join Date
    Jan 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCcompleter , colum probelm

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include <QMainWindow>
    6.  
    7. class QWidget;
    8. class QLineEdit;
    9.  
    10. class MyMainWindow :public QMainWindow
    11. {
    12. public:
    13. MyMainWindow( QWidget* parent = 0);
    14. QLineEdit* le ;
    15. };
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "MainWindow.h"
    2. #include <QLineEdit>
    3. #include <QCompleter>
    4. #include <QSqlTableModel>
    5. #include <QSqlDatabase>
    6.  
    7. MyMainWindow::MyMainWindow(QWidget* parent )
    8. {
    9. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    10. db.setHostName("localhost");
    11. db.setDatabaseName("any");
    12. db.setUserName("any");
    13. db.setPassword("any");
    14.  
    15. db.open();
    16.  
    17. le = new QLineEdit( this );
    18. model = new QSqlTableModel();
    19. model->setTable("Items");
    20. model->select();
    21.  
    22. QCompleter* cc = new QCompleter( this ) ;
    23. cc->setModel( model );
    24. cc->setCompletionColumn(2);
    25. cc->setCompletionMode(QCompleter::PopupCompletion);
    26. // cc->setCompletionMode(QCompleter::InlineCompletion);
    27. cc->setCaseSensitivity( Qt::CaseInsensitive );
    28. le->setCompleter(cc);
    29. }
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "MainWindow.h"
    3.  
    4. int main( int argc , char* argv[])
    5. {
    6. QApplication app(argc , argv );
    7.  
    8. // connectdb();
    9. MyMainWindow* mainWindow= new MyMainWindow;
    10. mainWindow->show();
    11.  
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    to run this code u need mysql server , u need to create the database with anyname , and a table called Items..
    well hope that helps

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCcompleter , colum probelm

    I can reproduce this error on my installation. It seems that setCompletionColumn() doesn't set a proper model column on the popup. A solution is to call:
    Qt Code:
    1. ((QListView*)cc->popup())->setModelColumn(2);
    To copy to clipboard, switch view to plain text mode 
    The funny thing is, that it should work without it just fine...

    This is the code that gets called:
    Qt Code:
    1. void QCompleter::setCompletionColumn(int column)
    2. {
    3. Q_D(QCompleter);
    4. if (d->column == column)
    5. return;
    6. #ifndef QT_NO_LISTVIEW
    7. if (QListView *listView = qobject_cast<QListView *>(d->popup))
    8. listView->setModelColumn(column);
    9. #endif
    10. d->column = column;
    11. d->proxy->invalidate();
    12. }
    To copy to clipboard, switch view to plain text mode 
    So there are three explanations:
    1. popup is not a QListView
    2. d->column == column
    3. QT_NO_LISTVIEW is defined

    First two assumptions are false (popup is a list view and d->column != column) and the third seems very unlikely. So there has to be a fourth explanation - something overrides or doesn't allow to change the model column for the listview.

  8. #8
    Join Date
    Jan 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCcompleter , colum probelm

    well thanks alot .
    it now works , the colum i want appear , but something starnge is happening..
    when the list popup , it don't handle keyboard evens well..
    for example when i write the first letter , and the list is poped up , i try to move by the keyboard down , it just moves to one item then refuse to go down anymore..
    the same happens when i try to go upwards , the pagedown and pageup don't work at all ?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.