Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

One person's error is another person's data.


devel / comp.lang.c++ / Re: c++ and qt

SubjectAuthor
* c++ and qtbubu
`- Re: c++ and qtwij

1
c++ and qt

<JCHnJeaPA53wht9GWCGXbKinvE0@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3051&group=comp.lang.c%2B%2B#3051

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!from-devjntp
Message-ID: <JCHnJeaPA53wht9GWCGXbKinvE0@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: c++ and qt
Newsgroups: comp.lang.c++
JNTP-HashClient: FbFuVLjp38b6EzSYWMp1bzq2RNg
JNTP-ThreadID: P_HnLIRgO7MRBwqIzMfYU0w2qnI
JNTP-Uri: http://news2.nemoweb.net/?DataID=JCHnJeaPA53wht9GWCGXbKinvE0@jntp
Supersedes: <-8iOTvKk5SuNaLhS37j6spnV6OA@jntp>
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Tue, 16 Jan 24 21:29:00 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Injection-Info: news2.nemoweb.net; posting-host="168b0b30881a359436f5afefe854379e61f00a0d"; logging-data="2024-01-16T21:29:00Z/8624637"; posting-account="227@news2.nemoweb.net"; mail-complaints-to="newsmaster@news2.nemoweb.net"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: bruno.do...@hotmail.fr (bubu)
 by: bubu - Tue, 16 Jan 2024 21:29 UTC

Hi,

Sorry for my bad english and sorry for my bad level in qt.

I would like to use a qml program and c++ libraries (with import).

I use Visual Studio on windows.
I want to use QT5 (not qt5)

I have several problems (and I put an example here-after) :
- how to use c++ with qml
- how to use a library written in c++ to use in a program in QML with
IMPORT statement.
- how to build executable and librarie with cmake?

My example is here :

main.qml

import QtQuick 2.15
import QtQuick.Controls 2.15
// import calculator ? ? ? how ?

ApplicationWindow {
visible: true
width: 400
height: 300
title: "Calculator"

Calculatrice {
id: calculatrice
}

Column {
anchors.centerIn: parent
spacing: 10

TextField {
id: input1
placeholderText: "Entrez le premier nombre"
validator: DoubleValidator {
bottom: -1000000000.0
top: 1000000000.0
}
}

TextField {
id: input2
placeholderText: "Entrez le deuxième nombre"
validator: DoubleValidator {
bottom: -1000000000.0
top: 1000000000.0
}
}

Row {
spacing: 10

Button {
text: "Additionner"
onClicked: {
resultLabel.text = "Résultat: " +
calculator.add(parseFloat(input1.text), parseFloat(input2.text))
}
}

Button {
text: "Soustraire"
onClicked: {
resultLabel.text = "Résultat: " +
calculator.subtract(parseFloat(input1.text), parseFloat(input2.text))
}
}

Button {
text: "Multiplier"
onClicked: {
resultLabel.text = "Résultat: " +
calculator.multiply(parseFloat(input1.text), parseFloat(input2.text))
}
}
}

Label {
id: resultLabel
text: "Résultat: "
}
}
}

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtCore>

#include "calculator.cpp"

int main(int argc, char* argv[])
{ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;

qmlRegisterType<Calculator>("Calculator", 1, 0, "Calculator");

QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);

return app.exec();}

calculator.h

// calculator.h
#ifndef CALCULATOR_H
#define CALCULATOR_H

class Calculator {
public:
double add(double a, double b) const;
double subtract(double a, double b) const;
double multiply(double a, double b) const;
};

#endif // CALCULATOR_H

calculator.cpp

#include <QObject>

class Calculator : public QObject
{
Q_OBJECT

public:
Q_INVOKABLE double add(double a, double b) const {
return a + b;
}

Q_INVOKABLE double subtract(double a, double b) const {
return a - b;
}

Q_INVOKABLE double multiply(double a, double b) const {
return a * b;
}
};

Could you help me, please.
It make errors on building. Why ?
How to build library for qml (using IMPORT) and executable with cmake ?

Sorry. I have a lot of problems. I will have others questions after.

Thanks a lot.

Re: c++ and qt

<de4846229c60f552f3c464baf8d2ce169e09a7f2.camel@gmail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3066&group=comp.lang.c%2B%2B#3066

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wynii...@gmail.com (wij)
Newsgroups: comp.lang.c++
Subject: Re: c++ and qt
Date: Sun, 21 Jan 2024 06:22:28 +0800
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <de4846229c60f552f3c464baf8d2ce169e09a7f2.camel@gmail.com>
References: <JCHnJeaPA53wht9GWCGXbKinvE0@jntp>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
Injection-Info: dont-email.me; posting-host="8df323a1f3c28d461bea728589a49547";
logging-data="4052985"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192qP3LKUWhXVuqSrxD4Eue"
User-Agent: Evolution 3.50.2 (3.50.2-1.fc39)
Cancel-Lock: sha1:+cum0D7+tx85hSiPmJK8e9U7BgQ=
In-Reply-To: <JCHnJeaPA53wht9GWCGXbKinvE0@jntp>
 by: wij - Sat, 20 Jan 2024 22:22 UTC

On Tue, 2024-01-16 at 21:29 +0000, bubu wrote:
> Hi,
>
> Sorry for my bad english and sorry for my bad level in qt.
>
> I would like to use a qml program and c++ libraries (with import).
>
> I use Visual Studio on windows.
> I want to use QT5 (not qt5)
>
> I have several problems (and I put an example here-after) :
> - how to use c++ with qml
> - how to use a library written in c++ to use in a program in QML with
> IMPORT statement.
> - how to build executable and librarie with cmake?
>
> My example is here :
>
> main.qml
>
> import QtQuick 2.15
> import QtQuick.Controls 2.15
> // import calculator ? ? ? how ?
>
>
> ApplicationWindow {
>     visible: true
>     width: 400
>     height: 300
>     title: "Calculator"
>
>     Calculatrice {
>         id: calculatrice
>     }
>
>     Column {
>         anchors.centerIn: parent
>         spacing: 10
>
>         TextField {
>             id: input1
>             placeholderText: "Entrez le premier nombre"
>             validator: DoubleValidator {
>                 bottom: -1000000000.0
>                 top: 1000000000.0
>             }
>         }
>
>         TextField {
>             id: input2
>             placeholderText: "Entrez le deuxième nombre"
>             validator: DoubleValidator {
>                 bottom: -1000000000.0
>                 top: 1000000000.0
>             }
>         }
>
>         Row {
>             spacing: 10
>
>             Button {
>                 text: "Additionner"
>                 onClicked: {
>                     resultLabel.text = "Résultat: " +
> calculator.add(parseFloat(input1.text), parseFloat(input2.text))
>                 }
>             }
>
>             Button {
>                 text: "Soustraire"
>                 onClicked: {
>                     resultLabel.text = "Résultat: " +
> calculator.subtract(parseFloat(input1.text), parseFloat(input2.text))
>                 }
>             }
>
>             Button {
>                 text: "Multiplier"
>                 onClicked: {
>                     resultLabel.text = "Résultat: " +
> calculator.multiply(parseFloat(input1.text), parseFloat(input2.text))
>                 }
>             }
>         }
>
>         Label {
>             id: resultLabel
>             text: "Résultat: "
>         }
>     }
> }
>
>
>
>
> main.cpp
>
> #include <QGuiApplication>
> #include <QQmlApplicationEngine>
> #include <QtCore>
>
> #include "calculator.cpp"
>
> int main(int argc, char* argv[])
> {
>   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);   
>   QGuiApplication app(argc, argv);   
>   QQmlApplicationEngine engine;    
>   
>   qmlRegisterType<Calculator>("Calculator", 1, 0, "Calculator");
>   
>   QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
>     &app, [url](QObject* obj, const QUrl& objUrl) {
>         if (!obj && url == objUrl)
>             QCoreApplication::exit(-1);
>     }, Qt::QueuedConnection);
>   engine.load(url);   
>
>   return app.exec();}
>
>
>
> calculator.h
>
>
> // calculator.h
> #ifndef CALCULATOR_H
> #define CALCULATOR_H
>
> class Calculator {
> public:
>    double add(double a, double b) const;
>    double subtract(double a, double b) const;
>    double multiply(double a, double b) const;
> };
>
> #endif // CALCULATOR_H
>
>
> calculator.cpp
>
> #include <QObject>
>
> class Calculator : public QObject
> {   
>    Q_OBJECT
>
> public:   
>    Q_INVOKABLE double add(double a, double b) const {       
>        return a + b;   
>    }   
>
>    Q_INVOKABLE double subtract(double a, double b) const {
>        return a - b;   
>    }   
>
>    Q_INVOKABLE double multiply(double a, double b) const {
>        return a * b;   
>    }
> };
>
>
>
> Could you help me, please.
> It make errors on building. Why ?
> How to build library for qml (using IMPORT) and executable with cmake
> ?
>
> Sorry. I have a lot of problems. I will have others questions after.
>
> Thanks a lot.
>

Check out this site. They are willingly to answer questions about Qt.
ttps://www.qtcentre.org/content/


devel / comp.lang.c++ / Re: c++ and qt

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor