Results 1 to 16 of 16

Thread: The gui is not start

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    20
    Thanks
    2

    Default The gui is not start

    When I start my program. It is run, but the paintEvent() is not executed. So the gui is not start.
    Any help will be appreciated.

    Qt: 4.5.1
    OS: redhat 6.0

    Sometimes it outputs the following log.
    X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
    Major opcode: 55 (X_CreateGC)
    Resource id: 0x2023c
    X Error: BadLength (poly request too large or internal Xlib length error) 16
    Major opcode: 11 (X_UnmapSubwindows)
    Resource id: 0x2023c
    X Error: BadRequest (invalid request code or no such operation) 1
    Extension: 255 (Uknown extension)
    Minor opcode: 0 (Unknown request)
    Resource id: 0x2023c

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The gui is not start

    Are you calling show() on the window/widget?
    Are you calling exec() on the application?
    Can you reproduce with a minimal main() that uses a standard widget, e.g. a QLabel?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2014
    Posts
    20
    Thanks
    2

    Default Re: The gui is not start

    My code is following.

    Qt Code:
    1. int main(int argc,char **argv)
    2. {
    3. qDebug()<<"Main Begin";
    4. QApplication app(argc,argv);
    5.  
    6. QWidget *widget=new QWidget;
    7.  
    8. widget->show();
    9. //widget->showFullScreen();
    10.  
    11. app.exec();
    12. delete widget;
    13. qDebug()<<"Main End";
    14. return 0;
    15. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The gui is not start

    That should work.
    It will be a very tiny window since you did not resize the widget, but it should show.

    Cheers,
    _

  5. #5
    Join Date
    Oct 2014
    Posts
    20
    Thanks
    2

    Default Re: The gui is not start

    I add QPixmap in GUI slot function. Maybe this is the root cause, because when I remove it, the GUI show.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The gui is not start

    Any relevant code you'd like to share?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The gui is not start

    When I start my program. It is run, but the paintEvent() is not executed. So the gui is not start.
    But from the code you shared -
    Qt Code:
    1. QWidget *widget=new QWidget;
    2.  
    3. widget->show();
    To copy to clipboard, switch view to plain text mode 

    You are creating a normal QWidget, and not a custom widget.
    So where do you expect the paintEvent to get hit ? How are you checking if paintEvent was hit,, and of which class ?

  8. #8
    Join Date
    Oct 2014
    Posts
    20
    Thanks
    2

    Default Re: The gui is not start

    Yes, the following is the simple code.

    main.h
    Qt Code:
    1. class MRender : public QThread
    2. {
    3. Q_OBJECT
    4. public:
    5. MRender(){}
    6. signals:
    7. void renderedPixmap(const QImage &image);
    8. protected:
    9. void run();
    10. };
    11.  
    12. class MCanvas : public QWidget
    13. {
    14. Q_OBJECT
    15. public:
    16. MCanvas(){}
    17. public slots:
    18. updatePixmap(const QImage &image);
    19. protected:
    20. void paintEvent(QPaintEvent *e);
    21. private:
    22. QPixmap pixmap_;
    23. };
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "main.h"
    2.  
    3. MRender::run()
    4. {
    5. while(1)
    6. {
    7. QPainter painter;
    8. QImage image(400,400,QImage::Formage_RGB32);
    9. image.fill(0xFFFFFF);
    10. painter.begin(&image);
    11. QRectF textRect(0,0,400,400);
    12. painter.drawText(textRect,Qt::AlignCenter,QString("Who are you?"));
    13. painter.end();
    14. emit renderedPixmap(image);
    15. sleep(1);
    16. }
    17. }
    18.  
    19. MCanvas::updatePixmap(const QImage &image)
    20. {
    21. pixmap_=QPixmap::fromImage(image);
    22. }
    23. MCanvas::paintEvent(QPaintEvent *e)
    24. {
    25. QPianter painter;
    26. painter.begin(this);
    27. painter.drawPixmap(0,0,pixmap_);
    28. painter.end();
    29. }
    30.  
    31. int main(int argc,char **argv);
    32. {
    33. QApplication app(argc,argv);
    34.  
    35. MCanvas canvas=new MCanvas;
    36. MRender render=new MRender;
    37.  
    38. QObject::connect(render,SIGNAL(renderedPixmap(const QImage &)),canvas,SLOT(updatePixmap(const QImage &)),Qt::DirectConnection);
    39.  
    40. QWidget *widget=new QWidget;
    41. QGridLayout *layout=new QGridLayout(widget);
    42. layout->addWidget(canvas);
    43. widget->setLayout(layout);
    44.  
    45.  
    46. widget->show();
    47. app.exec();
    48. delete widget;
    49. return 0;
    50. }
    To copy to clipboard, switch view to plain text mode 

    The porblem is "pixmap_=QPixmap::fromImage(image);" and "painter.drawPixmap(0,0,pixmap_);".

  9. #9
    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: The gui is not start

    You cannot create pixmap in threads other than the main thread. Your connect in line #38 cannot be a Qt::DirectConnection, it has to be Qt::QueuedConnection.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Oct 2014
    Posts
    20
    Thanks
    2

    Default Re: The gui is not start

    If use Qt::QueuedConnection, when I resize the window many times, but not release mouse, the buffer queued. And as I resize the window, it take up memory will be more and more, until I release mouse.

    And why you think it should use Qt::QueuedConnection?

  11. #11
    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: The gui is not start

    Quote Originally Posted by ugiwgh View Post
    If use Qt::QueuedConnection, when I resize the window many times, but not release mouse, the buffer queued.
    When you don't, your program doesn't work.

    And why you think it should use Qt::QueuedConnection?
    Because if you use direct connection, the slot is executed in the context of the caller, which happens to be the worker thread which cannot access pixmaps. I don't know where you copied the code from but if you have to copy someone's code then at least try to understand what it does.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Start a thread automatic at start
    By ralphot in forum Qt Programming
    Replies: 3
    Last Post: 10th July 2013, 15:54
  2. Cannot start app in Qt Creator
    By giantdragon in forum Newbie
    Replies: 1
    Last Post: 23rd May 2011, 21:32
  3. start
    By Sandeep in forum Newbie
    Replies: 1
    Last Post: 21st May 2008, 18:42
  4. ask: how to start app within app
    By rian191 in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2008, 06:53
  5. qwt examplesdo not start
    By pospiech in forum Qt Programming
    Replies: 3
    Last Post: 24th February 2008, 14:58

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.