Private slots issue [solved]



  • Hi everyone

    I am trying to follow the C++ GUI Programming with Qt4 book. Even the first example does not work for me.

    I tried to actually create a GUI application and add libraries such as <QLable>... etc.

    I really dont know why but if I add even one function under "private slots:", I will get these errors:

    symbol(s) not found for architecture x86_64

    linker command failed with exit code 1 (use -v to see invocation)

    Does anyone know if there is something wrong with my settings? Especially Build & Run section?

    I am running on Mac and
    Qt Creator 3.0.1
    Based on Qt 5.2.1(Clang 5.0 (Apple), 64 bit)

    Thanks


  • Moderators

    After you add your private slots, do:

    Build -> Run qmake

    Build -> Build Project



  • After Build "PROJECT_NAME", i get the same errors :(

    Does it have something to do with .pro file?


  • Moderators

    Oops, I just noticed:
    [quote author="Saham" date="1400279338"]
    Qt Creator 3.0.1
    Based on Qt 5.2.1(Clang 5.0 (Apple), 64 bit)[/quote]That is the version information for Qt Creator. But, what is your version of Qt? (Qt Creator is NOT Qt)

    Open Tools -> Options -> Build & Run -> Kits -- what do you see there? Did you download 32-bit Qt or 64-bit Qt?

    Also, can you please post your .pro file here?



  • I am using 64 on mac. The Kit is auto-detected:
    Name:
    Desktop Qt 5.2.1 clang 64bit
    Device:
    Run locally(default for Desktop)
    bCompiler:
    Clang(x84 64bin in /usr/bin)
    Debugger:
    System LLDB at usr/bin/lib
    Qt 5.2.1 Clang 64bit

    and here is the .pro file
    @

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = find
    TEMPLATE = app

    SOURCES += main.cpp
    finddialog.cpp

    HEADERS += finddialog.h

    FORMS += finddialog.ui
    @

    Thank you :)



  • Hi,

    just to be sure: The class to which you added the private slots inherits from QObject (maybe indirectly) and has the Q_OBJECT macro?!? I mean the class itself, not only its parents?!?

    I admit, the compiler errors don't really fit. But I wouldn't exclude the possibility that in a special situation these compiler error still occur. And it would be kind of the typical solution when you encounter problems as soon as you add signals and/or slots to your class.

    Best Soraltan



  • Hi

    Yes, I do have the following
    @
    class finddialog : public QDialog
    {
    Q_OBJECT
    ...
    @



  • Ok, so my guess is off the table. From what you have given us so far, I have no clue.

    What happens, when you add the same function under public slots:? Does it compile then?

    Could you give use the code and more of the compiler output?



  • "Here":https://github.com/mutse/qt5-book-code you can find examples for this book written on Qt5


  • Moderators

    Hmm, odd.

    Ok, do this:

    Open Qt Creator

    Select File -> New File or Project... -> Applications -> Qt Widgets Application (and then keep the default settings)

    Select Build -> Run

    What do you get?



  • Hi JKSH

    It runs fine. Simply a blank form :)



  • Hi Soraltan

    Here are the complete code:

    find.pro:
    @
    #-------------------------------------------------

    Project created by QtCreator 2014-04-30T23:08:06

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = find
    TEMPLATE = app

    SOURCES += main.cpp
    finddialog.cpp

    HEADERS += finddialog.h

    FORMS += finddialog.ui

    @
    finddialog.h:
    @
    #ifndef FINDDIALOG_H
    #define FINDDIALOG_H

    #include <QDialog>
    #include <QLabel>
    #include <QPushButton>
    #include <QLineEdit>
    #include <QCheckBox>
    #include <QWidget>
    #include <QHBoxLayout>

    namespace Ui {
    class finddialog;
    }

    class finddialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit finddialog(QWidget *parent = 0);
    ~finddialog();
    signals:
    void findNext(const QString &str,Qt::CaseSensitivity cs);
    void findPrevious(const QString & str,Qt::CaseSensitivity cs) ;
    private slots:

    void findClicked();
    void enableFindButton(const QString &text);
    private:
    Ui::finddialog *ui;
    QLabel label;
    QLineEdit lineEdit;
    QCheckBox
    caseCheckBox;
    QCheckBox
    backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
    QHBoxLayout *HLayout;

    };

    #endif // FINDDIALOG_H

    @

    finddialog.cpp:
    @
    #include "finddialog.h"
    #include "ui_finddialog.h"

    finddialog::finddialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::finddialog)
    {

    ui->setupUi(this);

    }

    finddialog::~finddialog()
    {
    delete ui;
    }

    @

    and main.cpp:

    @
    #include "finddialog.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    finddialog w;
    w.show();

    return a.exec();
    }

    @

    Do these help?

    Thanks



  • Hi,

    so looking at your code, here seem to be two private slots declared in the .h. Wehn you remove these the code compiles, when you add these the compiler complains, right?

    But there seems to be no definition in the .cpp file! This is probably what the linker complains about.

    Add a (even empty) definition for those in the .cpp file should help E.g.

    @
    void finddialog::findClicked(){
    }

    void finddialog::enableFindButton(const QString &text){
    }
    @
    Does that solve it?!?

    Best Soraltan



  • Hi Soraltan

    That fixed the issue. It's coming from my habit to run/compile as soon as I write one function. I did continue when I got the error ;)

    Thank you

    P.S. You will be my point of contact for future. I had asked this question in many places even on Faceboook. People tried really hard to help me but you got it right :)



  • Glad we found it.

    Please mark the thread a solved by prepending a [solved] in the title.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.