how can I run tests for QtQuick-Applications in the main.cpp? The main.qml have a rectangle and inside some buttons. The test class MouseClick.qml implements the javascript test functions who should push the buttons.
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QTestCase = QTestCase(MouseClick); //????
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/TestApp/main.qml"));
viewer.showExpanded();
return app.exec();
}
You can try to look how tests are implemented in Qt. For example
Related
I'm using QT5 and starting out with a basic Server/Client setup. I'm looking at going single threaded for both apps as there is no heavy processing on network data. Now, from everything I've read and researched here, when using asynchronous approach, you don't use waitForXXXX() otherwise it messes up all the signals and slots. The problem - On the client end, the connected() signal is either never emitted or never processed, even though the server consoles tells me that a new client has connected. I've been working on the same issue for 2 weeks now and couldn't find the exact same issue anywhere. I've stripped back both apps to the minimum and still no luck - also stripped out the UI part now - I just want see the console working. I have also tried switching to public slots and changing the signal/slot connection type and still have the same problem.
If you require code from the server, please let me know, but here is the basics of the client:
main.cpp
#include "QGameSocket.h"
#include <QtWidgets/QApplication>
#include <windows.h>
int main(int argc, char *argv[])
{
AllocConsole();
freopen( "conin$", "r", stdin );
freopen( "conout$", "w", stdout );
freopen( "conout$", "w", stderr );
QApplication a( argc, argv );
QGameSocket* pSocket = new QGameSocket();
return a.exec();
}
QGameSocket.h
#ifndef _QGAMESOCKET_H
#define _QGAMESOCKET_H
#include <QtNetwork/qtcpsocket.h>
#pragma comment ( lib, "Qt5Network.lib" )
class QGameSocket: public QObject
{
Q_OBJECT
public:
explicit QGameSocket( QObject* pParent = 0 );
~QGameSocket();
private slots:
void __OnConnected();
void __OnReadyRead();
private:
QTcpSocket* m_pSocket;
};
#endif
QGameSocket.cpp
#include "QGameSocket.h"
#include <qdatastream.h>
QGameSocket::QGameSocket( QObject* pParent ) :
QObject( pParent )
{
m_pSocket = new QTcpSocket();
connect( m_pSocket, SIGNAL( connected() ), this, SLOT( __OnConnected() ) );
connect( m_pSocket, SIGNAL( readyRead() ), this, SLOT( __OnReadyRead() ) );
const QString strHost = "127.0.0.1";
qDebug() << "Connecting to host ...";
m_pSocket->connectToHost( strHost, 27015 );
}
QGameSocket::~QGameSocket()
{
m_pSocket->deleteLater();
}
void QGameSocket::__OnConnected()
{
qDebug() << "Successfully connected to host!";
}
void QGameSocket::__OnReadyRead()
{
//handle messages
}
Any help would be much appreciated, thank you!
I finally figured it out - I was using the release network library, not the debug library.
I changed:
#pragma comment ( lib, "Qt5Network.lib" )
to
#pragma comment ( lib, "Qt5Networkd.lib" )
The customary way of passing values through argv in this declaration
int main(int argc, char* argv[]) {
is to pass it from your console through argv array into a program. I came across a situation where I wanted to achieve something different as follows. The program has the usual
int main(int argc, char* argv[]) {
declaration and inside my program I have a
function void foo(argv[1], 0).
Here is the layout and flow of my program's logic:
program ggg.cpp
:
void foo(char* x, int y) {
:
}//end foo
:
int main(int argc, char* argv[]) {
:
foo(argv[1], 0);
:
}//end main
(1) My normal method. Normally, when I compile the ggg.cpp program and my console input is:
ggg.exe . //the second input is a dot "."
the program runs fine (because argv[1] = '.' inside the program)
(2) However, I wanted to get innovative and execute the program as:
ggg.exe //here, the dot is not included
so that inside the program, I can assign the dot to argv[1] but I kept getting errors - no matter how I try other variations of the assignment statement.
By the way, I tried the assignment statement
argv[1]='.';
inside the main program (in method (2)) but it didn't work. I got an error message.
Background Information. I used to be very good in programming in my hay days but now I have forgotten a lot of things because I left coding for a very long time to do other things.
I'm trying to use QtXmlPatterns module in order to parse an XML file.
Unfortunately using Qt5.1 on MacOsX 10.7&10.8 I found a problem I have not with Qt4.8.5.
#include <QCoreApplication>
#include <QGuiApplication>
#include <QXmlQuery>
#include <QStringList>
#include <QDebug>
int main(int argc, char *argv[])
{
//QGuiApplication a(argc, argv);
QCoreApplication a(argc, argv);
QXmlQuery qry;
qry.setQuery("doc(\"file.xml\")");
QStringList lst;
qry.evaluateTo(&lst);
qDebug() << lst;
return 0;
}
this is the .pro I'm using.
QT += core gui xmlpatterns
TARGET = Test
TEMPLATE = app
CONFIG -= app_bundle
SOURCES += main.cpp
If I run a QCoreApplication everything works properly, instead if I switch on QGuiApplication (or a QApplication) this small program hangs forever on the evaluteTo function. It doesn't matter if file.xml exists or not.
On Windows and on Linux the same program run smoothly even if I use the QCoreApplication or the QGuiApplication or the QApplication.
I tried also to play a little with the QXmlQuery functions. If I call the setFocus function I got the same behaviour (with QCoreApplication everything it's ok, with QGuiApplication it hangs for ever on the setFocus function).
Suggestions?
Is there any way to pop up a wxWidget dialog for selecting files in a command line procedure?
I am new to wxWidgets programming and it seems straightforward to pop up a selecting file dialog with FileDialog class in a wx app.
Here is my c++ code and it works fine within a wx app procedure but not in a command line one.
#include
//#include "wx/osx/filedlg.h"
#include "wx/wx.h"
#include
using namespace std;
//IMPLEMENT_APP(MyApp)
int main(int argc, const char * argv[])
{
wxFileDialog OpenDialog(NULL, wxEmptyString, wxEmptyString, wxEmptyString,
_("*"),
wxFD_MULTIPLE);
// Creates a "open file" dialog with 4 file types
if (OpenDialog.ShowModal() == wxID_OK) // if the user click "Open" instead of "cancel"
{
wxArrayString wx_str_arr;
OpenDialog.GetFilenames(wx_str_arr);
/*
for(size_t i=0; i<wx_str_arr.GetCount(); ++i)
{
wxString str = wx_str_arr.Item(i);
cout<<"str["<<i<<"] = "<<str.c_str().AsChar()<<endl;
}
*/
cout<<"count:"<<wx_str_arr.GetCount()<<endl;
}
return 0;
}
You must initialize wxWidgets correctly for this to work, see wxInitializer class for how to do it in console application.
Note that under Unix, including OS X, there is really absolutely no difference between console and GUI applications, this distinction only exists under Windows.
I am working with visual studio 2005...
Can anybody tell me how to write most basic program for addition of two numbers in google test??
I have gone through almost all the references given...but somehow didnt understand how to get started?
The following would be about as basic as it can get:
#include "gtest/gtest.h"
int GetSum(int a, int b) { return a + b; }
TEST(MathsFunctions, GetSum) {
ASSERT_EQ(3, GetSum(1, 2));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
You need to provide the path to gtest's include directory and link to gtest.lib