Results 1 to 7 of 7

Thread: GUI locking problem

  1. #1
    Join Date
    Dec 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default GUI locking problem

    Hi all,

    I am having problems with my GUI interface. It constantly keeps locking for a few seconds. My application is not a pure cpp application it has event handling mechanism which is implemented in C. From main function in C code I create guimain thread which than runs and send events to C code.

    Main function in C looks like this:

    int main(int argc, char *argv[])
    {
    .......do some stuff......
    gui_init(argc, argv, (void*)&gui_sync);

    while(!device_shutdown)
    {
    process_message_queues(5);
    }
    pthread_join( gui_t, NULL);
    return 0;
    }

    CPP code

    EXT_C int gui_init( int argc, char *argv[], void *gui_sync)
    {
    myargc = argc;
    myargv = argv;
    pthread_attr_init(&gui_attr);
    pthread_create(&gui_t, &gui_attr, guimain, (void *)gui_sync);
    return 0;
    }

    void *guimain( void* lpParam )
    {
    char *defaultargs[2];
    struct gui_sync_t *sync = (struct gui_sync_t*)lpParam;

    QApplication app( myargc, myargv );
    main1=new formMain;
    main1->setGeometry(0,0,240,320);
    main1->show();
    setTargetWidget(main1);
    app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );

    sync->ready=1;
    return (void*)app.exec();
    }

    When I run this application on my device I get following warning:
    WARNING: QApplication was not created in the main() thread.

    Does anyone has any idea?

    Tnx,
    Benjamin

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GUI locking problem

    The warning is quite clear, I think.
    You do create the QApplication object in a thread that is not the main thread of the application. (I don't know if that will cause trouble. But probably it will, otherwise the Trolls would not have put that warning in, I guess.)

    Any reason in particular why you want to put the gui not in the main thread?

  3. #3
    Join Date
    Dec 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: GUI locking problem

    Well I am not quite sure how to create QApplication object from C code.

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GUI locking problem

    from C code? you can't really - except by calling C++ code.

    I see two ways to go:
    i) make main.c into a main.cpp (should be no problem, right?)
    ii) call from main.c setupAndRunGui()

    where
    Qt Code:
    1. // gui.h
    2. extern "C" int setupAndRunGui();
    3.  
    4. // gui.cpp
    5. int setupAndRunGui(int &argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8. // whatever else you need to setup
    9. return app.exec(); // note that this is a blocking call
    10. }
    To copy to clipboard, switch view to plain text mode 

    iii) I would suggest you create a "normal" Qt app.
    * a C++ main that creates a QApplication object
    * create a QThread that does your C event polling/handling
    * send Qt custom events for that events from your C code (if the gui needs to act upon those)

    HTH

  5. #5
    Join Date
    Dec 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: GUI locking problem

    Thank you

  6. #6
    Join Date
    Jul 2012
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: GUI locking problem

    Hi,
    I am new qt programmer. I make a program run qt_browser demos. I use this program to call this part code:

    Q_INIT_RESOURCE(data);
    BrowserApplication application(qtArgc, (char**)qtArgv);
    if (!application.isTheOnlyBrowser())
    return 0;
    application.newMainWindow();
    exit = application.exec();

    I call the first, it is OK, but when I close mainwindows and call again, it do not run and display "WARNING: QApplication was not created in the main() thread"
    , then system is quited.
    Anyone help me?
    Thanhs

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: GUI locking problem

    Please do not double-post and/or resurrect long dead threads.
    This question has its own thread

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.