Linking button and tab



  • Hello. Im new to nokiaQT and may be noob. Please be patient with me as Im trying very hard to learn QT. I wanted to create an application where if i click the button if will display that particular tab. So far from my look out from the net I found out about
    void QTabWidget::tabMoved and it gives an invalid use of qualified name. Please help.

    Header
    @#ifndef MAINMENU_H
    #define MAINMENU_H

    #include <QMainWindow>
    #include <QTabBar>
    #include <QTabWidget>

    namespace Ui {
    class mainmenu;
    }

    class mainmenu : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit mainmenu(QWidget *parent = 0);
    ~mainmenu();

    private:
    Ui::mainmenu *ui;

    private slots:
    void on_btnIdentify_clicked();
    };

    #endif // MAINMENU_H
    @

    main.cpp
    @#include <QtGui/QApplication>
    #include "mainmenu.h"
    #include <QTabBar>
    #include <QTabWidget>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    mainmenu w;
    #if defined(Q_WS_S60)
    w.showMaximized();
    #else
    w.show();
    #endif

    return a.exec&#40;&#41;;
    

    }
    @

    Mainmenu.cpp
    @#include "mainmenu.h"
    #include "ui_mainmenu.h"
    #include "QTabBar"
    #include <QTabWidget>

    mainmenu::mainmenu(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::mainmenu)
    {
    ui->setupUi(this);
    connect(ui->btnIdentify, SIGNAL(clicked()), this, SLOT(on_btnIdentify_clicked()));
    }

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

    void mainmenu::on_btnIdentify_clicked()
    {
    void QTabWidget::tabMoved ( 0, 1 );
    }
    @



  • Please guide me.TQ



  • tabMoved is not a member of QTabWidget. The compiler should have told you so.

    Do you have any experience with C++ at all?



  • So far I only done simple program on MFC C++ using OpenCV, Volker.read image , display image and stuff like that.Very little experience.
    i thought tabmoved is a function. Where I just need to include the QTab and then call it out as a function. Because in Visual Studio C++ once i link with OpenCv. i just require to call the function i wanted and link with the button as a caller.

    Volker can you please kindly tell me what to do like .just tell me what to do and where i must put the code? You dont have to give me the source code.just tell me what is needed ..TQ



  • Here is so far what I discover.
    @void mainmenu::on_btnIdentify_clicked()
    {
    QTabBar * movement = new QTabBar; //Creating a new object
    movement->moveTab(0,1); // object calling the attribute
    }@

    There is a few changes in my code. I try to explain what I understand. Please guide me if im wrong. QTabBar is the class and the object is call movement. This object call movement have the attribute of moveTab (basically moving tab value 0 to 1). I have compile and show no error. When I click the button it show no changes.

    1. DId i have wrong coding ?
    2. Am I using the wrong function ?
      May expectation is that when I click the button from tab value 0 it would straight away show me the new tab which is tab value 1.


  • I have no clue about MFC (and I do not want to learn it either). But I can give you some advise:

    get you some good introduction in C++ - there are numerous out there, both printed and online

    be sure to understand C++ basics (pointers, references, objects, attributes and methods, static methods, inheritance....)

    go to http://doc.qt.nokia.com/4.7/index.html and read the introduction to Qt. There are some getting started guides as well (translations are available in the "wiki":http://developer.qt.nokia.com/wiki/Getting_Started)

    understand the basic principles behind Qt (event loop, signals, slots, QObject, QWidget, just to name a few)

    start with simple programs that to learn the basics and move to the more advanced functions later on

    actually read the docs, especially the API docs!

    It seems you're doing it just the other way round. You'll have no success this way.



  • bq. It seems you’re doing it just the other way round. You’ll have no success this way.

    I dont quite understand what you mean in the last sentence. Did my child and parent got mix up ? or the class and object got the other round it.



  • It seems like you're not using the API correctly. Make sure you've read what the members of QTabBar and QTabWidget are in http://doc.qt.nokia.com/4.7/index.html .
    Then, can you fix up your code in the first post or add a new post with your new code.
    Then I can fix it up for you.
    Hard to work with things like "void QTabWidget::tabMoved ( 0, 1 );" because doesn't make any sense. That's why people asked if you know C++ at all. You can't call a function with a type (eg. void) and you can't call such a function with a scope (::) but instead a variable type QTabWidget test; test->tabMoved(0, 1); and also, tabMoved is not a member of QTabWidget. So a lot of issues there.
    If you show a more accurate code, I can fix it for you but I don't know what you want with this yet.

    • Sacha


  • XSacha I had already change the code already. Thanks for your advice

    @void mainmenu::on_btnIdentify_clicked()
    {
    QTabBar * movement = new QTabBar;
    movement->moveTab(0,1);
    }@

    What I wanted to do is that I put a button on a tabwidget ( first tab). When I click the button it will automatically bring me to the same tabwidget but is on the second tab now.

    My idea is using the moveTab function. Where if the value if the first tab which is 0 switch with the second tab value which is 1. I would expect them to switch places. If moveTab is not the correct function what is the name of the function ? as I had look through the link you gave me. Cannot find any revelant function which could switch tabs.



  • Well can you show a more complete code example?

    You do realise that there needs to be some lines of code in between the creation and the move right?

    @void mainmenu::on_btnIdentify_clicked()
    {
    QTabBar * movement = new QTabBar;
    ...
    movement->moveTab(0,1);
    }@

    To move a tab there first needs to be tabs.
    See:
    http://doc.qt.nokia.com/latest/qtabbar.html#addTab



  • Sorry for the late reply xsacha. I had class. For this project I did the interface using QT creator. Im uploading the screenshot of the two form and the XML ui for your ease. Please look into my mistake. because in Visual Studio i can just create the interface and insert coding to the button (function). The photo source are uploaded inside facebook and I just copy the link image location.If can view please tell me. I will upload in some other place.

    The first picture is the first tab with the current index 0. where if i click the button it suppose to bring me the second tab
    : http://a6.sphotos.ak.fbcdn.net/hphotos-ak-ash4/196272_1854906168872_1127350995_32234075_6333144_n.jpg

    Second tab with the current index 1
    :http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash4/188488_1854907608908_1127350995_32234079_6382975_n.jpg

    XML Coding
    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>mainmenu</class>
    <widget class="QMainWindow" name="mainmenu">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>392</width>
    <height>401</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>mainmenu</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QTabWidget" name="tabWidget">
    <property name="minimumSize">
    <size>
    <width>363</width>
    <height>383</height>
    </size>
    </property>
    <property name="currentIndex">
    <number>1</number>
    </property>
    <widget class="QWidget" name="tab1">
    <property name="layoutDirection">
    <enum>Qt::LeftToRight</enum>
    </property>
    <attribute name="title">
    <string>Main Menu</string>
    </attribute>
    <widget class="QPushButton" name="btnIdentify">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>60</y>
    <width>120</width>
    <height>100</height>
    </rect>
    </property>
    <property name="minimumSize">
    <size>
    <width>91</width>
    <height>61</height>
    </size>
    </property>
    <property name="maximumSize">
    <size>
    <width>120</width>
    <height>100</height>
    </size>
    </property>
    <property name="focusPolicy">
    <enum>Qt::TabFocus</enum>
    </property>
    <property name="autoFillBackground">
    <bool>false</bool>
    </property>
    <property name="styleSheet">
    <string notr="true"/>
    </property>
    <property name="text">
    <string>Identify Disease</string>
    </property>
    </widget>
    </widget>
    <widget class="QWidget" name="tab_2">
    <attribute name="title">
    <string>Identify Disease</string>
    </attribute>
    <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
    <widget class="QLabel" name="label">
    <property name="text">
    <string>In construction</string>
    </property>
    </widget>
    </item>
    </layout>
    </widget>
    </widget>
    </item>
    </layout>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    @


Log in to reply
 

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