Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Qt creates a main.o file he cannot execute

  1. #1
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Qt creates a main.o file he cannot execute

    Hi all. I found the World Time Clock Example | Qt 4.8 and tried to create it with my Qt Creator. Documentation gives many files but no main.cpp available. Seems strange !
    I created the main.cpp missing (see code below). The project compiles well, but, at the execution, (which is available) he says "no executable specified". Does it mean "cannot execute this main.o" ?? Here is the code of my main.cpp
    #include <QApplication>
    #include "worldtimeclock.h"
    #include "worldtimeclockplugin.h"
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    WorldTimeClock clock;
    #if defined(Q_OS_SYMBIAN)
    clock.showMaximized();
    #else
    clock.show();
    #endif
    return app.exec();
    }


    Sorry, I don't find how to tag the above code !

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    "main.o" is not an executable program. It is a binary object file resulting from compilation of your main.cpp, and needs to be linked with other object files and run-time libraries to create the executable.

    You have apparently configured your Qt project incorrectly in Qt Creator or the .pro file. Without more information it is impossible to tell what you did wrong. I am very surprised that the world time example did not have a file containing a "main()" function (The file does not have to be called "main.cpp") or a .pro file that is configured correctly.

    Edit: Are you trying to build the World Time Clock Plugin example? This project does not build an executable program, it builds a Qt Designer plugin library. You cannot add a main() function to it and create a runnable executable.
    Last edited by d_stranz; 1st December 2016 at 19:10.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    The documentation gives :
    Files:

    designer/worldtimeclockplugin/worldtimeclock.cpp
    designer/worldtimeclockplugin/worldtimeclock.h
    designer/worldtimeclockplugin/worldtimeclockplugin.cpp
    designer/worldtimeclockplugin/worldtimeclockplugin.h
    designer/worldtimeclockplugin/worldtimeclockplugin.pro
    I made the error to put all of them in my project. It created many .o files , the first being main.o. Maybe if I suppress some of the above files I will be able to see the famous clock !!

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    Maybe if I suppress some of the above files I will be able to see the famous clock !!
    No. The project is configured to build a Qt Designer plugin.

    If you copy the worldtimeclock.h and worldtimeclock.cpp files (and nothing else from the plugin project) into a new project that builds an executable GUI app, edit worldtimeclock.h to remove the "QT_DESIGNER_EXPORT" macro from the class definition, and create an instance of the WorldTimeClock widget as your apps, window, then you will be able to see it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    I am so curious to see that clock, that I will try what you say. It is a big job indeed. Thank you very much.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    It isn't a big job at all:

    Qt Code:
    1. // main.cpp
    2.  
    3. #include <QApplication>
    4. #include "WorldTimeClock.h"
    5.  
    6. int main( int argc, char * argv[] )
    7. {
    8. QApplication app( argc, argv );
    9. WorldTimeClock c;
    10. c.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Add main.cpp, worldtimeclock.cpp, and worldtimeclock.h to a Qt project, compile it, and run.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    I removed the "QT_DESIGNER_EXPORT" as you told me but many errors appear. I also pasted your new main.I am unable to go further. Here is the code (no # available):
    //mainwindow.h
    Qt Code:
    1. #ifndef WORLDTIMECLOCK_H
    2. #define WORLDTIMECLOCK_H
    3.  
    4. #include <QTime>
    5. #include <QWidget>
    6. #include <QtUiPlugin/QDesignerExportWidget>//error:No such file or directory
    7. class QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. explicit WorldTimeClock(QWidget *parent = 0);
    13.  
    14. public slots:
    15. void setTimeZone(int hourOffset);
    16.  
    17. signals:
    18. void updated(QTime currentTime);
    19.  
    20. protected:
    21. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
    22. private:
    23. int timeZoneOffset;
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 4th December 2016 at 08:08. Reason: missing [code] tags

  8. #8
    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: Qt creates a main.o file he cannot execute

    Quote Originally Posted by sylas View Post
    I removed the "QT_DESIGNER_EXPORT" as you told me but many errors appear.
    Obviously also remove the include that would be needed for the designer plugin that you are no longer building.
    Also remove the QDESIGNER_WIDGET_EXPORT, as its name suggests it is also needed for the designer plugin, which you are no longer using.

    Quote Originally Posted by sylas View Post
    Here is the code (no # available)
    Yes, there is. Did you switch to Advanced mode?
    In any case you can also type the tags: [code][/code] and the code in-between

    Cheers,
    _

  9. #9
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    I made what you told me. No clock appears (run available). Compile output : Elapsed time: 00:03 Application Output: exited code 0 Issues: too many remarks. My O.S. is Linux 16. Strange enough, I have another project of another clock named "Analog Clock" ; It shows very well. I give you my last code of the header:
    Qt Code:
    1. //worldtimeclock.h
    2. #ifndef WORLDTIMECLOCK_H
    3. #define WORLDTIMECLOCK_H
    4. #include <QTime>
    5. #include <QWidget>
    6. //#include <QtUiPlugin/QDesignerExportWidget>//error:No such file or directory
    7. class //QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. explicit WorldTimeClock(QWidget *parent = 0);
    13.  
    14. public slots:
    15. void setTimeZone(int hourOffset);
    16.  
    17. signals:
    18. void updated(QTime currentTime);
    19.  
    20. protected:
    21. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
    22. private:
    23. int timeZoneOffset;
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 5th December 2016 at 09:30. Reason: fix code tags

  10. #10
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    Excuse me. Compiler finds errors in main.cpp(you gave me). aotnd the header file(modified on your demand). I am tired and I am not experieced enough with Qt Creator.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    class //QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget
    You are obviously not very experienced with C++ either. This code comments out everything after the word "class" on this line, which obviously won't compile. When we say "remove QDESIGNER_WIDGET_EXPORT" we mean exactly that: delete the letters "Q T D E S I G N E R _ W I D G E T _ E X P O R T", then save the file.

    I wrote a program for you in a previous post in this thread. If you follow our instructions instead of trying to do your own thing, that program would work. It is almost exactly the same as the AnalogClock example, except you substitute a "WorldTimeClock" widget for the "AnalogClock" widget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. #12
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    Only one error but a jumping error. First in the header, line 22. Compiler doesn't know Q_DECL_OVERRIDE. Where is it ? It is i the file worldtimeclockplugin. I add this new header. At last the error is QtUiPlugin/QDesignerExportWidget. Please tell me, did you see this clock ? I doubt i will ever see this clock.

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    You need three source files in your project (and only these three):

    1 - main.cpp (which I have given you)
    2 - worldtimeclock.h (which comes from the plugin project)
    3 - worldtimeclock.cpp (which comes from the plugin project)

    and no other source code files. Edit worldtimeclock.h to delete this line:

    #include <QtUiPlugin/QDesignerExportWidget>

    and to delete QDESIGNER_WIDGET_EXPORT. Delete Q_DECL_OVERRIDE if the compiler complains about it.

    Save the file. Build the project. Run it. See your clock.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  14. #14
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    Still only one error. This time in "WorldTimeClock.cpp" . Error in line 15. Lokk at the comment please. Here is the code:
    Qt Code:
    1. //WorldTimeClock.cpp
    2. #include "WorldTimeClock.h"
    3. #include <QMouseEvent>
    4. #include <QPainter>
    5. #include <QTimer>
    6.  
    7. WorldTimeClock::WorldTimeClock(QWidget *parent)
    8. : QWidget(parent)
    9. , timeZoneOffset(0)
    10.  
    11. {
    12. typedef void (QWidget::*WidgetUpdateSlot)();
    13.  
    14. QTimer *timer = new QTimer(this);
    15. connect(timer, &QTimer::timeout, this, static_cast<WidgetUpdateSlot>(&QWidget::update));
    16. //above line:no matching function for call to "WorldTimeClock::connect(QTimer*&,void(QTimer::*)(),WorldTimeClock*,void(QWidget::*)()
    17. // ::*)()'
    18. timer->start(1000);
    19.  
    20. setWindowTitle(tr("World Time Clock"));
    21. resize(200, 200);
    22. }
    23.  
    24. void WorldTimeClock::paintEvent(QPaintEvent *)
    25. {
    26. static const QPoint hourHand[3] = {
    27. QPoint(7, 8),
    28. QPoint(-7, 8),
    29. QPoint(0, -40)
    30. };
    31. static const QPoint minuteHand[3] = {
    32. QPoint(7, 8),
    33. QPoint(-7, 8),
    34. QPoint(0, -70)
    35. };
    36.  
    37. QColor hourColor(127, 0, 127);
    38. QColor minuteColor(0, 127, 127, 191);
    39.  
    40. int side = qMin(width(), height());
    41. QTime time = QTime::currentTime();
    42. time = time.addSecs(timeZoneOffset);
    43.  
    44. QPainter painter(this);
    45. painter.setRenderHint(QPainter::Antialiasing);
    46. painter.translate(width() / 2, height() / 2);
    47. painter.scale(side / 200.0, side / 200.0);
    48.  
    49. painter.setPen(Qt::NoPen);
    50. painter.setBrush(hourColor);
    51.  
    52. painter.save();
    53. painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
    54. painter.drawConvexPolygon(hourHand, 3);
    55. painter.restore();
    56.  
    57. painter.setPen(hourColor);
    58.  
    59. for (int i = 0; i < 12; ++i) {
    60. painter.drawLine(88, 0, 96, 0);
    61. painter.rotate(30.0);
    62. }
    63.  
    64. painter.setPen(Qt::NoPen);
    65. painter.setBrush(minuteColor);
    66.  
    67. painter.save();
    68. painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
    69. painter.drawConvexPolygon(minuteHand, 3);
    70. painter.restore();
    71.  
    72. painter.setPen(minuteColor);
    73.  
    74. for (int j = 0; j < 60; ++j) {
    75. if ((j % 5) != 0)
    76. painter.drawLine(92, 0, 96, 0);
    77. painter.rotate(6.0);
    78. }
    79.  
    80. emit updated(time);
    81. }
    82.  
    83. void WorldTimeClock::setTimeZone(int hourOffset)
    84. {
    85. timeZoneOffset = qMin(qMax(-12, hourOffset), 12) * 3600;
    86. update();
    87. }
    To copy to clipboard, switch view to plain text mode 

  15. #15
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    Remove line 12. Change line 15 to:

    Qt Code:
    1. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  16. #16
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    Hurrah ! I can see the clock. Thank you very much. Another day I will look for the way to display the legal time of LosAngeles.

  17. #17
    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: Qt creates a main.o file he cannot execute

    Line 15 should have also worked without the static_cast.
    Qt Code:
    1. connect(timer, &QTimer::timeout, this, &QWidget::update);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  18. #18
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    I am always looking for help.I should like to change my local time. I thought if was in line: , timeZoneOffset(0) that is line 9. I changed the 0 in the parenthesis, but nothing happens. I don't see where else I should act. Thanks for your help.

  19. #19
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creates a main.o file he cannot execute

    Line 15 should have also worked without the static_cast.
    Yes. I didn't see the point of the typedef or static_cast in the first place. I posted the old style connect() because I wasn't sure if the OP was using Qt4 or Qt5.

    I changed the 0 in the parenthesis, but nothing happens.

    time = time.addSecs(timeZoneOffset);
    This statement implies that the time zone offset is expressed in seconds. The setTimeZone() method converts hours to seconds appropriately, so call that with the offset in hours instead of changing the value in the WorldTimeClock constructor:

    Qt Code:
    1. // main.cpp
    2.  
    3. #include <QApplication>
    4. #include "WorldTimeClock.h"
    5.  
    6. int main( int argc, char * argv[] )
    7. {
    8. QApplication app( argc, argv );
    9. WorldTimeClock c;
    10. c.setTimeZone( -8 ); // Los Angeles - PST
    11. c.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  20. #20
    Join Date
    Nov 2016
    Posts
    48
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt creates a main.o file he cannot execute

    Magnific ! You are a lion !

Similar Threads

  1. to execute a .m file in qt on ubuntu OS
    By CRL in forum Qt Programming
    Replies: 8
    Last Post: 6th June 2015, 12:19
  2. How to execute my .css file in Qt?
    By harish in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2011, 11:12
  3. Execute a .sql file with more than one query
    By ShadowBelmolve in forum Newbie
    Replies: 6
    Last Post: 19th August 2010, 16:48
  4. How to execute an exe file from Qt application
    By maveric in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2008, 10:24
  5. Replies: 1
    Last Post: 15th February 2006, 22:17

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.